Computer Science, asked by tejal3791, 11 months ago

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

Answers

Answered by vcharithacherry
2

Answer:

#include <stdio.h>

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.

Similar questions