Write a recursive function that calculate sum of first n natural numbers.

Source Code

#include <stdio.h>

int sum(int);

int main()
    int number;

    printf("Enter a positive integer :");
    scanf("%d", &number);

    printf("The sum of first %d numbers is %d.", number, sum(number));

    return 0;

int sum(int n)
    if (n == 0)
        return 0;
        return n + sum(n - 1);


Enter a positive integer :10
The sum of first 10 numbers is 55.