B.Sc. CSIT 1st Semester C Programming

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

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;

}

About Author

ICT BYTE