AD1

Tuesday, 15 November 2016

write a recursive function to calculate the sum of the first 25 natural numbers

solution 

#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;
}
view raw sum25.c hosted with ❤ by GitHub

No comments:

Post a Comment