Subscribe

RSS Feed (xml)

Tuesday, February 9, 2010

Write a C program to compute the sum of the terms 1+2+3+.....upto N terms

#include< stdio.h>
#include< conio.h>
int main()
{
int n,i,sum=0;
clrscr();
printf("Enter the 'n' value:");
scanf("%d",&n);
for(i=1; i<=n; i++)
{
sum=sum+i;
}
printf("\nSum of the 'n' terms: %d",sum);
getch();
return 0;
}

1 comment: