Given a variable n refers to a positive int value, use two additional variables, k and total to write a for loop to compute the sum of the cubes of the first n counting numbers, and store this value in total. thus your code should put 1*1*1 + 2*2*2 + 3*3*3 +... + n*n*n into total. use no variables other than n, k, and total.

Respuesta :

tonb
You could do it like this (example for n=5).

int n = 5;
int total = 0;
for (int k = 1; k <= n; k++) total += k*k*k;

ACCESS MORE