//Find Larger of two num. using Function
#include<stdio.h>
#include<conio.h>
int max(int a,int b);
main()
{
int x,y;
printf("Enter any two number:");
scanf("%d%d",&x,&y);
max(x,y);
}
int max(int a,int b)
{
if(a>b)
printf("A is greater");
else
printf("B is greater");
getch();
}
Enter any two number:250
520
B is greater
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);.