calculating sum of numbers between two user inputs

Came across this question and am finding it difficult to imagine how the program would work. I cant figure out how to calculate the values between numbers that a user types in.

This is the question:
Write a function which takes two parameter of integer type and both parameters are positive integer. These number should be provided by the user of your program. The first parameter is lower than the second parameter. You function should be able to calculate the sum of the square of each of the numbers between the two inputs and should display that. Please write a main function to display the working of your function. Call the function at least three times by using some loop in the main function.

Could you post your code? We can look at that and see where the issue is.
1
2
sum (a -> b)
return ((b * -~b) >> 1) - ((a * -~a) >> 1)
Topic archived. No new replies allowed.