Fundamentals of Computer Programming - Old Questions
4. Write a program that uses a “for” loop to compute and prints the sum of a given numbers of squares.
6 marks
|
Asked in 2065
#include<stdio.h>
int main()
{
int i, n, sum=0;
printf("Enter n value: ");
scanf("%d", &n);
for(i=0; i<=n; i++)
{
sum += (i*i);
}
printf("Sum of squares of first %d natural numbers = %d", n, sum);
return 0;
}