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 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.

LANGUAGE: C++

CHALLENGE:

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 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.

SOLUTION:

The Bad News: The content you are trying to access is only available to members.

The Good News: You too can be a member, simply Click Here.

Already a member?

Posted in ,

6 Comments

  1. Paul on November 9, 2014 at 12:06 pm

    It specifically says to use a for loop…

  2. annon243 on February 7, 2015 at 9:31 am

    total = 0;
    for (k=1; k<=50; k++){
    total += k*k;
    }

  3. Malcolm A. Morgan on February 19, 2016 at 4:18 am

    HERE IS THE C CODE:

    k = 1;
    total = 0;

    while (k<=50)
    {
    total += (k*k);
    k++;
    }

  4. John on October 20, 2016 at 2:52 pm

    for the for loop

  5. John on October 20, 2016 at 2:52 pm

    total = 0;
    for (k =1; k <= 50; k++){
    total += k*k;

    }

  6. dardan on February 22, 2017 at 12:34 pm

    what would be the answer for visual basics

Leave a Comment

You must be logged in to post a comment.