Skip to content

Instantly share code, notes, and snippets.

@avii-7
Created August 26, 2021 10:50
Show Gist options
  • Save avii-7/8d93c537f370e154a7fc02666204db9a to your computer and use it in GitHub Desktop.
Save avii-7/8d93c537f370e154a7fc02666204db9a to your computer and use it in GitHub Desktop.
Write a recursive function to obtain the running sum of first 25 natural numbers
#include <stdio.h>
int sum(int);
int main()
{
int num;
printf("Enter a number: ");
scanf("%d", &num);
printf("\nSum of first %d number is: %d\n", num, sum(num));
return 0;
}
int sum(n) int n;
{
return (n == 1) ? 1 : n + sum(n - 1);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment