given int variables k and total that have already been declared , use a do...while loop to compute the sum of the squares of the first 50 positive integers 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. view keyboard shortcuts

Respuesta :

Every counting number's square is added to the total total by multiplying it by (k*k); this causes the value of k to increase and the next counting number to be reached.

Compute the programm?

The c++ program for the given scenario is as follows.

#include

using namespace std;

int main() {

  int k, total;

  k=1;

  total=0;

  while(k<=50)  

  {

Every counting number's square is added to the total total by multiplying it by (k*k); this causes the value of k to increase and the next counting number to be reached.

k++; cout "Sum of squares of first 50 counting numbers is "; total "Sum of squares of first 50 counting numbers is 42925"

Explanation:

K and total are the only variables used in the program, as already explained. Integer data types are specified for these variables.

Initial values for variable total are 0, and for variable k are 1.

k=1;

   total=0;

Variable k is used to represent counting number whose square is added to the variable total. Hence, values are taken accordingly.

The while loop is also known as the pre-test loop. This loop first evaluates the given condition and executes if the condition is satisfied.

  while(k<=50)  

The above while loop will execute till the value of variable k is less than or equal to 50. Once the value of k exceeds 50, the loop gets terminated. The loop executes 50 times, beginning from the value of 1 till k reaches 50.

The value of k is squared and added to the variable total each time the loop executes.

total = total + (k*k);

After the square is added to total, value of variable k is incremented by 1. This new value represents the next counting number.

k++;

After 50 executions of the loop, total variable will hold the sum of the squares of all the numbers from 1 to 50. The sum is displayed at the end.

This program implements the simplest logic for calculation of sum using two variables. The other loops such as for loop and do-while loop only differ in the placement and/or evaluation of the test condition.

To learn more about While loop refer to:

https://brainly.com/question/19344465

#SPJ4