Write a program that find the larger of two number using function :-

//Find Larger of two num. using Function

int max(int a,int b);
int x,y;
printf("Enter any two number:");

int max(int a,int b)
printf("A is greater");
printf("B is greater");



Enter any two number:250
B is greater


Declare function to find maximum:-

Here,we will embed the logic to find maximum within a function. Let us define function to find maximum.
1. First give a meaningful name to our function. Say max() function is used to find maximum between two numbers.
2. Second, we need to find maximum between two numbers. Hence, the function must accept two parameters of int type say, max(int a, int b).
3. Finally, the function should return maximum among given two numbers. Hence, the return type of the function must be same as parameters type i.e. int in our case.
After combining the above three points, function declaration to find maximum is int max(int a, int b);.

Previous Next

NOTE:- You can also use variable argument list to find maximum or minimum between two or more variables at once.