$(document).ready(function() { $('pre code').each(function(i, block) { hljs.highlightBlock(block); }); });

Sunday, July 11, 2010

Addition using recursion

#include
#include
int add(int);
void main()
{
int num,sum=0;
clrscr();
printf("How many no.s do u wanna add:");
scanf("%d",&num);
printf("\nEnter the no.s here:");
sum=add(num);
printf("The sum of the no.s is %d",sum);
getch();
}

int add(int x)
{
int n;
scanf("%d",&n);
if(x==0)
return(0);
else if(x==1)
return(n);
else
return(n+add(x-1));
}

No comments:

Post a Comment

Contact Me

Name

Email *

Message *