1.

C program to find sum of squares of n natural numbers using while loop

Answer»

ANSWER:

#include

int main()

{

   int n, i, sum = 0;

   printf("ENTER a positive INTEGER: ");

   scanf("%d",&n);

   i = 1;

   while ( i <=n )

   {

       sum += i;

       ++i;

   }

   printf("Sum = %d",sum);

   return 0;

}

Explanation:

the loop is iterated n number of times. And, in each iteration, the value of i is ADDED to sum and i is incremented by 1.



Discussion

No Comment Found