C Program to Find The Sum of First n Natural Numbers Using Recursion

#include<conio.h>
#include<stdio.h>

int sumseries(int n)
{
int sum=0;

if(n==0)
return 0;

return (n+sumseries(n-1));

}

void printseries(int n)
{

if(n==0)
return 0;

else
printf("% d",n);

printseries(n-1);

}

void main()
{
int num;
clrscr();
printf("Enter The No. Of Elements Of The Series  :  ");
scanf("%d",&num);
printseries(num);
printf("\n\nPrinting Sum  :  %d",sumseries(num));

getch();

}
Share on Google Plus

About Akash Manhas

This is a short description in the author block about the author. You edit it by entering text in the "Biographical Info" field in the user admin panel.
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment