Created
August 26, 2021 10:50
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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