this program will get two integers from the user. The program will 1. call getPr
ID: 3878357 • Letter: T
Question
this program will get two integers from the user. The program will
1. call getProduct(int, int, int &); where the first two arguments
are the two input integers and third one is the product of these 2
integers.
2. call printEvenAscending(int, int); where the two arguments are the
two input integers. This function will print all even numbers between
the two arguments in an ascending order. Note, the two input integers
could be in any order (such as 34, 70 or 90, 5). It is your job to
check which argument is larger.
3. call print5Rand(int, int); where the two arguments are the two input
integers. The function will print 5 random numbers between the two
areguments(inclusive). for example. pinrt5Rand(99, 21); will print
5 random integers between 21 and 99 (inclusively).
You need complete printEvenAscending and print5Rand functions.
Questions: (Please answer it in this comment section)
q1. What is the purpose of the “cin” statements?
Ans:
q2. What is the purpose of the “cout” statements?
Ans:
*/
#include <iostream>
using namespace std;
void GetProduct ( int A, int B, int & Product );
int main()
{
int First, Second, PROD;
cout << "Input two integers ";
cin >> First >> Second;
GetProduct( First, Second, PROD );
cout << PROD << endl;
system("pause");
return 0;
}
void GetProduct ( int A, int B, int & Product )
{
Product = A * B;
}
Explanation / Answer
program:--
#include <iostream>
#include <cstdlib> //for rand() function
using namespace std;
void GetProduct ( int A, int B, int & Product );
void printEvenAscending(int, int); //prototype
void print5Rand(int, int); //prototype
int main()
{
int First, Second, PROD;
cout << "Input two integers ";
cin >> First >> Second;
GetProduct( First, Second, PROD );
cout << PROD << endl;
printEvenAscending(First, Second); //call for even numbers
print5Rand(First, Second); //call for random numbers
system("pause");
return 0;
}
void GetProduct ( int A, int B, int & Product )
{
Product = A * B;
}
void print5Rand(int a, int b)
{
if(a>b) //if a is big swap a,b
{
int temp=a;
a=b;
b=temp;
}
cout<<"5 random numbers between "<<a<<" and "<<b<<" are: "<<endl;
for (int i=0;i<5;i++)
{
int num=rand() % (b-a) + a +1; //generate a random number between a and b (inclusively)
cout<<num<<" "; //print number
}
cout<<endl;
}
void printEvenAscending(int a, int b)
{
if(a>b) //if a is big swap a,b
{
int temp=a;
a=b;
b=temp;
}
cout<<"even numbers between "<<a<<" and "<<b<<" are: "<<endl;
for (int i=a+1;i<b;i++) //list numbers between a and b
if(i%2==0) //check if number divisible by 2 or not for check even
cout<<i<<" "; //if divisible print number
cout<<endl;
}
output1:--
Input two integers 34 70
2380
even numbers between 34 and 70 are:
36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68
5 random numbers between 34 and 70 are:
39 69 68 38 51
Press any key to continue . . .
output2:--
Input two integers 90 5
450
even numbers between 5 and 90 are:
6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88
5 random numbers between 5 and 90 are:
46 27 49 70 49
Press any key to continue . . .
q1 ans:-- cin is used to read from console
q2 ans:-- cout is used to write to console
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.