Find largest number using function is simple program which we are implementing using functions in c++.
In this tutorial we will see what is function, c++ program find largest number using function.
What is function : function is block of code.
How to Find greater number using function
First we declare function which finds greater number , we define function by finding max number and we call function from main function by passing two numbers to function.
Algorithm
- Start
- Define function which finds large number
- Write main function
- Take two number input
- Pass number and call function
- End
C++ program to find largest number using function
12345678910111213141516171819 | #include <iostream>using namespace std;int large(int x, int y);int main(){ int a,b;cout<<“Enter 2 numbers\n”; cin>>a>>b; int res = large(a, b); // Function call cout<<“Greater number is = “<<res; return 0;}int large(int x, int y) // Function Definition{ return( x>y?x:y );} |
Output :

Explanation :
1. Execution starts with the main function.
2. Declare variable
a , b => to numbers
3. Take two numbers input.
cin>>a>>b; => a= 12 , b =10
4.Call function to find max
large(a, b); => function executed
int large(int x, int y){ x= 12 , y= 10
return( x>y?x:y ); => 12>10 => condition true so x returned
} => returned to main function
5. Print greater value
cout<<“Greater number is = “<<res;
=> Greater number is = 12