Skip to content

luc050.c

Problem Statement

Write a recursive function to obtain the sum of first 25 natural numbers.

Metadata

Property Detail
Author Amit Dutta amitdutta4255@gmail.com
Date 08 Feb 2026
License MIT License (See the LICENSE file for details)

Actions

Raw View on GitHub

💡 You can print or save this file by opening Raw and using your browser.

Source Code

#include <stdio.h>
#include <math.h>
#include <stdlib.h>

int get_sum(int);

int main()
{
    int n = 25, sum;

    sum = get_sum(n);
    printf("Sum of first %d natural numbers is: %d\n", n, sum);

    return 0;
}

int get_sum(int n)
{
    if (n == 0)
        return 0;
    else
        return n + get_sum(n - 1);
}