Sunday, October 23, 2011

Sum Of Natural Numbers

#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