Pages

Sum of 10 natural numbers through for loop

//Sum of 10 natural numbers through for loop.


#include<stdio.h>
#include<conio.h>

void main()
{
  int num1=0,i;
  clrscr();
  for(i=1;i<=10;i++)
  {
  num1=num1+i;
  }
  printf("Sum of natural numbers upto 10 is: %d",num1);
  getch();
}

Output:

Sum of natural numbers upto 10 is: 55

No comments:

Post a Comment