13.3k views
1 vote
Use the variables k and total to write a while loop that computed the sum of the squares of the first 50 counting numbers, and assigns that value to total. Thus your code should assign 1*1+2*2+3*3+...+49*49+50*50 to total. Use no variables other than k and total.

1 Answer

1 vote

Final answer:

To compute the sum of the squares of the first 50 counting numbers using the variables k and total, use a while loop.

Step-by-step explanation:

To compute the sum of the squares of the first 50 counting numbers using the variables k and total, you can use a while loop. Here's an example:

k = 1
total = 0

while k <= 50:
total += k * k
k += 1

In this code, k starts from 1 and increases by 1 in each iteration. The variable total is updated by adding the square of k in each iteration. At the end of the loop, total will contain the sum of the squares of the first 50 counting numbers.

User LucasF
by
8.0k points