find the sum of first ten natural numbers

11. Write a program to find the sum of first ten natural numbers?
#include
#include
void main()
{
int i=1,sum=o;
clrscr();
while(i<=10)
{
sum=sum+i;
i++;
}
printf("sum is %d", sum);
getch();
}


Algorithum
1.start
2.check the number is less than or equal to 10
3.calculate the sum of 10 natural numbers
4.print sum
5.stop


Result
The program is sucessfully executed and desired output is obtained

Output
55

0 comments:

Post a Comment