- 1
C++ program to sum up from x to y
Someone please write a code that will prompt the user to enter two numbers and add up the numbers from the first number to the second number e.g if num1 is 1 and num2 is 9, answer= 1 +2+3+4+5+6+7+8+9 Just help me with the steps and method of the loop Thank you🤗
3 odpowiedzi
+ 1
Where is your code? Please post your try
0
Junaid Bashir check which input is smaller using if statement... next you have to loop through smaller one to bigger one and add number into some variable called result...at the end of loop, your result variable in which you were adding all numbers is the output
0
you could create a function with a loop. Just create a variable that the function will return (I'll call it result). keep incrementing result by the smaller one plus the loop counter (initialized with zero) until the loop counter reach the different between the bigger one and the smaller one.