Saturday, 21 January 2012

To Add first n numbers using Function / Recursion



#include<stdio.h>
#include<conio.h>
void main()
{
int sum(int);
int n,s;
clrscr();
printf("enter n numbers\n");
scanf("%d",&n);
s=sum(n);

printf("The sum of n numbers=%d",s);
getch();
}
int sum(int n)
{
int i,sum=0;
for(i=0;i<=n;i++)
{
sum=sum+i;
}
return sum;
}



For 8051 microcontroller programming :http://assemblylanguage8051.blogspot.in/

Rupee Fall : The Real Reasons by JayHind

No comments:

Post a Comment