(Write in C++)
Write a program that reads in two numbers and, if the input is valid, outputs 2 times the product of the integers that lie between the two values (including the values themselves). If either number is not an integer, or if the first number is not less than the second number, just output an error message. The sample runs below should give the idea. User inputs are in bold. Important Notes: Your program should use a loop to calculate the sum, i.e. you will lose marks if you use a formula to calculate the product. It should just deal with just one set of inputs and stop.
First example (the output is twice the product of
5*6*7* 8 *9*10):
Enter two integers (smaller number first): 5 10
Twice the product of the integers in between
these values is: 302400
Second example (the first number is not less than the
second number):
Enter two positive integers (smaller number first): 10 6
You did not follow the instructions!
Third example (one or both values are not
integers):
Enter two positive integers (smaller number first): 6.5 10
You did not follow the instructions!
l want solve neccessary please
C++ program
Source code:
//C++ Program
//Sum of Natural Numbers in a given range
#include<iostream>
using namespace std;
//main Program
int main()
{
int mul = 1, upper_limit, lower_limit;
cout << "Enter two positive integers:\n";
cin >> lower_limit;
cin >> upper_limit;
if(upper_limit>lower_limit){
//calculating product of numbers in the given range
for(int i = lower_limit; i <= upper_limit; i++)
mul *= i;
//printing output
cout<<"Twice the product of integers between "
<< lower_limit << " to " << upper_limit << " is:\n" << mul*2;
}
else{
cout<<"You did not follow the instuction\n";
}
return 0;
}
The output
Get Answers For Free
Most questions answered within 1 hours.