Blogger templates

Pages

Sunday, 6 May 2012

C Program: Find the Sum of First 'n' Integers by using While Statement

sum logo

Statement of C Program:  Calculate the sum of First 'n' Integers :

 
#include<stdio.h>
#include<conio.h>
void main()
{
int N,b ;
sum=0;
clrscr();

printf("Enter the value of N\n ");
scanf("%d" ,&N);
b=1;
while(b<=N)
{
sum=sum+b;
// sum+=b
b++;
}
printf(" Sum=%d\n" , sum);
}
Output:
Enter the value of N
10
Sum=55


0 comments:

Post a Comment