Nepal's #1 Tech Blog

, ,

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

604,807 views 10,080 likes

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: %dn", n, sum_of_squares);

return 0;

}

Visited 24 times, 1 visit(s) today