answersLogoWhite

0

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

16y ago

What else can I help you with?

Related Questions

Is addition exothermic or endothermic?

Addition of numbers is neither exothermic nor endothermic because it does not involve any chemical reactions or energy transfers between substances. It is a mathematical operation performed to find the sum of two or more numbers.


What is the difference between subtraction and addition?

Subtraction involves taking away a number from another number, while addition involves combining two or more numbers to find a total sum. Subtraction results in a smaller number, while addition results in a larger number.


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.


Addition and subtraction are examples of what are best called?

Addition and subtraction are examples of arithmetic operations, specifically binary operations. These operations involve combining two numbers to produce a single result. In mathematics, addition is considered an operation that combines two numbers to find their sum, while subtraction is an operation that finds the difference between two numbers. Both addition and subtraction are fundamental operations in arithmetic and are used extensively in various mathematical applications.


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.