write a recursive function to calculate the sum of the first 25 natural numbers
solution
This file contains 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> | |
#include <stdlib.h> | |
#include <ctype.h> | |
#include <math.h> | |
#include <stdbool.h> | |
int sum25() | |
{ | |
static int sum=0; | |
static int t=25; | |
if(t>=0) | |
{ | |
sum+=t; | |
t--; | |
sum25(); | |
} | |
return sum; | |
} | |
int main() | |
{ | |
printf("%d",sum25()); | |
return 0; | |
} |
No comments:
Post a Comment