Siddharth S. answered 12/24/20
Here to help you!!
Hi Tri,
What is the logic that you are trying to follow? If you have to find the sum of 12 + 22 + . . . + n2.. . You need to get the number 'n' from the end-user and run a for loop to get the sum. Here is the algorithm that you can follow:
int sum = 0; // Define a variable 'sum' to get the cumulative sum
//Following loop is to check if value of n greater than zero.
while loop( condition(n>0){
sum = sum + n2.
n-- //Decrement value of n
}
Hope this helps!!