181k views
2 votes
Given int variables k and total that have already been declared, use a while loop to compute the sum of the squares of the first 50 counting numbers and store this value in total.

User Champer Wu
by
3.2k points

1 Answer

3 votes

Answer:

Following are the statement is given below

Int total=0; // variable declaration

int k=1; // variable declaration

while(k<=50) // iterating the loop

{

total=total+k*k; // calculating sum of the squares

k++; // increment the value of k

}

Step-by-step explanation:

Following are the description of the above statement

  • Declared a variable total and k of int type.
  • Initialized total to 0 and k to 1.
  • iterating the while loop up to the value 50.
  • In this while calculating the calculating sum of the squares in the total variable.
  • increment the value of k by 1. This loop is executed until 50.
User Maverick
by
2.9k points