answersLogoWhite

0


Best Answer

First of all we will describe how our program should be working.

After entering number 1 and 5 I want it count 2 + 3 + 4 and return 9. After entering 4 and 9 it should count 5 + 6 + 7 + 8 and return 26. After entering X and X I should get 0. If I enter X and X - 1 I should get and error.

Here is the code of such application:

#include

int main() {

int firstNum, secondNum, sum, tmp;

printf("Please enter first number: ");

scanf("%d", &firstNum);

printf("Please enter second number: ");

scanf("%d", &secondNum);

if (secondNum < firstNum) {

printf("Sorry, second number must be higher than first one.\n");

return 1;

}

sum = 0;

for (tmp = firstNum + 1; tmp < secondNum; tmp++) {

sum += tmp;

}

printf("All numbers between %d and %d sum equals %d\n", firstNum, secondNum, sum);

return 0;

}

Testing:

Please enter first number: 1

Please enter second number: 5

All numbers between 1 and 5 sum equals 9

Please enter first number: 4

Please enter second number: 9

All numbers between 4 and 9 sum equals 26

User Avatar

Wiki User

15y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How do you find out addition of all numbers between two inputed numbers in for loop?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

How do you work out missing number addition if the bottom number is smaller than the top number?

you find out missing numbers in addition by subtracting the numbers that are writen


Combining two or more numbers to find the sum is called?

Combining two or more numbers to find the sum is called addition.


You use this to find out how much two or more numbers are together?

A calculator. Addition.


How do you find arithmetic mean between two numbers?

Add the two numbers and divide by two, or find the number which is halfway between the two numbers.


How do you find the sum for addition?

Add all the numbers together and that's the sum. The sum is the answer.


One numbers 3 times another numberthe difference between the numbers 10 Find the numberswhat are answer?

One numbers 3 times another number.the difference between the numbers 10. Find the numbers.


How do you find irrational numbers between 0 and 1?

the numbers between 0 and 1 is 0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,0.10.


How do you write a VBnet program to find the prime numbers between 100 to 200?

VBnet program to find the prime numbers between 100 to 200?


How do you insert rational numbers between two rational numbers?

Find the arithmetic average of the two rational numbers. It will be a rational number and will be between the two numbers.


What does find the difference between?

to subtact the two numbers


Find rational numbers between 0 and -1?

There exists infinite number of rational numbers between 0 &amp; -1.


How do you put in codes for action replay for Pokemon ruby?

it is pretty easy all you do is add the game to the list if it is not already there then once it is inputed you exit out to the list of games and find the game you just inputed once you have done that press the add button on the right side of the device and add the (m) code first and then the ret of the codes it is pretty easy!!!!!!!!!!!!!!!!!!!!!!!