119k views
1 vote
g Write a function named find_min that takes two numbers as arguments and returns the minimum of the two. (Behavior is not specified for which to return, if they are even -- we won't test that case.) For example: Given 2 and 4, the function returns 2 as the minimum.

User Shikiju
by
3.0k points

1 Answer

5 votes

Answer:

Following are the code to the given question:

#include <iostream>//header file

using namespace std;

void find_min(int x,int y)//defining a method find_min that takes two parameters

{

if(x<y)//use if to check x less than y

{

cout<<x;//print value x

}

else//else block

{

cout<<y;//print value y

}

}

int main()//main method

{

int x,y;//defining integer variable

cout<<"Enter first number: ";//print message

cin>>x;//input value

cout<<"Enter second number: ";//print message

cin>>y;//input value

find_min(x,y);//calling method

return 0;

}

Output:

Enter first number: 4

Enter second number: 2

2

Explanation:

In this code, a method "find_min" that takes two integer variable "x,y" in its parameters and use if block to check its value and print is value.

In the main method, we declared two integer variable "x,y" that takes value from user-end, and pass the value into the method that prints its calculated value.

User Webish
by
3.6k points