Question
C++
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.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

The c++ code for the above question is :

#include<iostream>
using namespace std;

void getProduct(int, int, int&);
void printEvenAscending(int, int);
void print5Rand(int, int);

int main()
{
int a, b, result;
 cout<<"enter the 1st integer: ";
 cin>>a;
 cout<<"enter the 2nd integer: ";

cin>>b;

getProduct(a, b, result);

printEvenAscending(a, b);

print5Rand(a, b);
return 0;
}

//function to find the product of 2 numbers 
void getProduct(int a, int b, int& result)
{
        result = a * b;
    cout <<"Product is :"<< a << " * " << b << " = " << result << endl;

}

 
//function to print all the even numbers between 2 numbers in ascending order
void printEvenAscending(int a, int b)
{
   int numstart, numend;
  if(a<b)
   {
     numstart=a;
     numend=b;
   }
   else
   {
   numstart=b;
     numend=a;
   }
   cout<<"Even numbers between "<<a<<" and "<<b<<" are : "<<endl;
   while (numstart <= numend)
        {
                if (numstart % 2 == 0)
                {
                        cout << numstart<<" ";
                }
                numstart++;
        }
   cout<<endl;
}
 
//function to print 5 random numbers between 2 numbers entered 
void print5Rand(int a, int b)
{
  int numrand, high, low;
  if(a>b)
  {
    high=a;
    low=b;
  }
  else
  {
    high=b;
    low=a;
  }
  cout<<"random numbers generated between "<<a<<" and "<<b<<" are : "<<endl;
  for(int i=0; i<5; i++)
  {
    numrand = (rand()%(high - low)) + low + i;
    cout << numrand << "  ";
  }
}

The sample output for the above code is given below. It works well for any 2 given integer values. Please hit the "like" button if this helped. Good luck!

input enter the lst integer: 55 enter the 2nd integer: 37 Product is :55 * 37 2035 Even numbers between 55 and 37 are : 38 40

Add a comment
Know the answer?
Add Answer to:
C++ this program will get two integers from the user. The program will 1. call getProduct...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • C programing Write a program to sort numbers in either descending or ascending order. The program...

    C programing Write a program to sort numbers in either descending or ascending order. The program should ask the user to enter positive integer numbers one at a time(hiting the enter key after each one) The last number entered by the user should be -1, to indicate no further numbers will be entered. Store the numbers in an array, and then ask the user how to sort the numbers (either descending or ascending). Call a function void sortnumbers ( int...

  • Write a C Program that inputs an array of integers from the user along-with the length...

    Write a C Program that inputs an array of integers from the user along-with the length of array. The program then prints out the array of integers in reverse. (You do not need to change (re-assign) the elements in the array, only print the array in reverse.) The program uses a function call with array passed as call by reference. Part of the Program has been given here. You need to complete the Program by writing the function. #include<stdio.h> void...

  • 1. Write a program that asks the user to enter two integers, obtains the numbers from...

    1. Write a program that asks the user to enter two integers, obtains the numbers from the user, then prints the larger number followed by the words “is larger.” If the numbers are equal, print the message “These numbers are equal.” Use only the single-selection form of the if statement you learned in this chapter.

  • LANGUAGE = C i. Write a program that takes int numbers from user until user gives...

    LANGUAGE = C i. Write a program that takes int numbers from user until user gives a sentinel value (loop terminating condition). Sort the numbers in ascending order using Insertion sort method. Sorting part should be done in different function named insertionSort(). Your code should count the number of swaps required to sort the numbers. Print the sorted list and total number of swaps that was required to sort those numbers. (4 marks) ii. In this part take another number...

  • IN C++ ADD COMMENTS AS MUCH AS POSSIBLE Exercise 1: Duplicate the Arrays Suppose you are...

    IN C++ ADD COMMENTS AS MUCH AS POSSIBLE Exercise 1: Duplicate the Arrays Suppose you are developing a program that works with arrays of integers, and you find that you frequently need to duplicate the arrays. Rather than rewriting the array-duplicating code each time you need it, you decide to write a function that accepts an array and its size as arguments. Creates a new array that is a copy of the argument array, and returns a pointer to the...

  • 1. (40 pts) Note: All programs MUST run in Ubuntu. Following the example C program in...

    1. (40 pts) Note: All programs MUST run in Ubuntu. Following the example C program in Folio consisting of three files (a.c, a.h, main.c), write a C program that consists of three files mysquare.h, mysquare.c andmyMain.c. Below is the mysquare.h prototype #include <stdlib.h> #include <stdio.h> void generateNums(int *myarr, int len); void squareNums(int *myarr, int len); void printNums(int *myarr, int len); mysquare.h must contain only the function declarations (prototypes) listed above generateNums function should generate len random integers in the range...

  • In C++: Write a program that reads a list of integers, and outputs the two smallest...

    In C++: Write a program that reads a list of integers, and outputs the two smallest integers in the list, in ascending order. The list is preceded by an integer indicating how many numbers are in the list. If the input is: 5 10 5 3 21 2, the output is: 2 3 To achieve the above, first read the integers into a vector.

  • 2. Write a Marie program that accepts two positive (inputs) two integers and outputs the sum...

    2. Write a Marie program that accepts two positive (inputs) two integers and outputs the sum of both of the integers and all the numbers in between Write a Marie program that determines the largest of a series of positive integers provided by a user. The user will enter a -1 when she is finished. Up to 10 numbers will be provided by the user. Write a Marie program that accepts two positive integers, multiples them by repeated addition, and...

  • Question: In C++ Write a correct and complete C++ program th... Bookmark In C++ Write a...

    Question: In C++ Write a correct and complete C++ program th... Bookmark In C++ Write a correct and complete C++ program that inputs 20 integer values from the user and performs three calculations. In the main function, input the values from the user. As part of your answer, write a sub-function, named calcAvg (), which takes two arguments and returns the average of all the integers. Also write another sub-function, named reverseArray (), which takes two arguments and reverses the...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT