Use two variables k and total to write a for loop to compute the sum of the squares of the first 50 counting numbers, and store this value in total. Thus, your code should put 1*1 + 2*2 + 3*3 +... + 49*49 + 50*50 into total. Use no variables other than k and total.

Respuesta :

Answer:

total = 0 #intialize the first variable total.

for k in range(51):#for loop which use the second variable k.

   total=total+(k*k)#calculate the value.

Explanation:

  • The above defined a statement that is said by the question and it is written in python language.
  • The above have one variable total which calculates the value of the square of 1 to 50.
  • It is because the for-loop runs from 0 to 50 and calculates the value in total by the help of the last expression which uses the total and k variable.
  • It is because the k variable holds every value for for-loop.

Answer:

Following are the statement in the C++ Language  

int total=0; // variable declaration

int k;// variable declaration

for(k=0;k<50;k++) // iterating the for loop

{

   total=total+k*k;// perform operation  and calculating square of 50 number

}

Explanation:

Following is the description of the statement  

  • Declared a variable "total" and "k" of the "int" type initialized the total variable with the value 0.
  • Iterating the for loop for calculating the squares of the first 50 counting numbers. So we will execute the loop less then 50 .
  • In this loop, we counted the square of 50 number in the "total" variable.
ACCESS MORE
EDU ACCESS