sum of n number(while loop)

Sum of n number using while loop

C program to find sum of n number enter from user using while loop.

   






Method followed in program

  1. Take the input from the user to find sum of number.
  2. Declared variable and initialize it with variable 0.
  3. Apply the condition for while loop.
  4. Execute the statement inside program to find sum.
  5. Finally print the sum of enter number.


   Sum of n number


#include<stdio.h>
#include<conio.h>
void main()
{
  clrscr();
  int num,sum=0,i;
  printf("Enter number\n");
  scanf("%d",&num);
  i=1;
  while(i<=num)
  {
     sum=sum+i;
  }
 printf("sum is %d",sum);
 getch();
}

sum of n number(while loop) sum of n number(while loop) Reviewed by Deepak kumar soni on December 30, 2018 Rating: 5

No comments:

Powered by Blogger.