Thursday 26 January 2012

Write a c program to find the sum of 1+2+3+.....+n

#include<stdio.h>
#include<conio.h>
void 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();
}

No comments:

Post a Comment