C program to find sum of squares of n natural numbers using while loop
Answers
Answered by
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
Math,
6 months ago
Computer Science,
11 months ago
Computer Science,
11 months ago
Science,
1 year ago