Saturday, 13 December 2014

C PROGRAM FOR SUM OF 1ST TEN NATURAL NUMBERS

Write a program to find the Sum of 1st ten natural numbers by using (do-while statement):

 #include<stdio.h>
#include<conio.h>
int main()
{
int i=1,sum=0, N;
clrscr();
printf("Enter the first ten natural number");
scanf("%d",&N);
do
{
sum=sum+i;
i++;
}
while(i<=10);
printf("Sum of 1st ten natural number is %d",sum);
getch();
return(0);
}

OUTPUT:
Enter the first ten natural number
1 2 3 4 5 6 7 8 9 10

Sum of 1st ten natural number is 55

No comments:

Post a Comment