Write a C program to input two or more numbers from user and find maximum and minimum of the given numbers using functions. How to find maximum and minimum of two or more numbers using functions in C programming.
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);
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);.