Sum
of First n natural numbers.
#include<stdio.h>
#include<stdio.h>
int sum(int)
{
Int s=0,i=1;
while(i<=n)
{
s=s+I;
I=i+1;
}
return(s);
}
Void main()
{
Int k,s;
printf(“Enter the
required no:”);
k=sum(5);
printf(“%d”,k);
getch();
}
Output: 15
No comments:
Post a Comment