178k views
0 votes
Write the definition of a function printLarger, which has two int parameters and returns nothing. The function prints the larger value of the two parameters to standard output on a single line by itself.

1 Answer

2 votes

Answer:

  1. #include <iostream>
  2. using namespace std;
  3. void printLarger(int a, int b){
  4. if(a > b){
  5. cout<<a;
  6. }else{
  7. cout<<b;
  8. }
  9. }
  10. int main()
  11. {
  12. printLarger(4, 5);
  13. return 0;
  14. }

Step-by-step explanation:

The solution code is written in C++.

Firstly define a function printLarger that has two parameters, a and b with both of them are integer type (Line 5). In the function, create an if condition to check if a bigger than b, print a to terminal (Line 7-8). Otherwise print b (Line 9-10).

In the main program, test the function by passing 4 and 5 as arguments (Line 16) and we shall get 5 printed.

User Jhonny
by
4.1k points