Sum of N integer using recursion

/*sum of N integer using recursion*/
#include <stdio.h>
int sum(int n);
int number, result;
printf("Enter a positive integer: ");
scanf("%d", &number);
result = sum(number);
printf("sum = %d", result);
return 0;
int sum(int n)
if (n != 0)
// sum() function calls itself
return n + sum(n-1);
return n;

Leave a Reply

Your email address will not be published. Required fields are marked *

Enter Captcha Here : *

Reload Image