Write a program that uses a “for” loop to compute and prints the sum of a given
numbers of squares.

Last Updated on by ICT BYTE

Write a program that uses a “for” loop to compute and prints the sum of a given
numbers of squares.

#include<stdio.h>

int main() {
int n;
int sum_of_squares = 0;

printf("Enter the number of squares: ");
scanf("%d", &n);

for (int num = 1; num <= n; num++) {
    int square = num * num;
    sum_of_squares += square;
}

printf("The sum of %d squares is: %d\n", n, sum_of_squares);

return 0;

}

More From Author

Write a program for the interest charged in installments for the following case. A cassette player costs Rs. 2000. A shopkeeper sells it for Rs. 100 down payment and Rs. 100 for 21 more months. What is the monthly interest charged?

write a program in c to generate the following matrics: A = [ 3 5 7 2 −3 4 4 5 2 ] , B = [ 7 6 6 −5 4 3 ]