This is the simple program in C language to find the greatest of three numbers with the help of else if, this program is based on a functional approach.
Algorithm
- Take input three numbers from user.
- Call function with these three parameters.
- Perform a condition to find greatest number by function.
- Retrun the greatest number.
- Hold the greatest return value by function.
- Print the greatest number of the three numbers.
Source code:
// c program to find the greatest of three numbers
#include <stdio.h>
//fucntion to check greatest among three number
int greatest(int num1, int num2, int num3){
if(num1>num2 && num1>num3){
return num1;
}
else if(num2>num1 && num2>num3){
return num2;
}
else{
return num3;
}
}
//driver function
int main(){
//define variables used in program
int num1, num2, num3, max;
//take input form user
printf("\n******Greatest Number Finder******");
printf("\n\nEnter First number:");
scanf("%d",&num1);
printf("\nEnter second number:");
scanf("%d",&num2);
printf("\nEnter Third number:");
scanf("%d",&num3);
//call function and hold return value in max variable
max = greatest(num1,num2,num3);
//print the greatest number
printf("\n\n%d is the greatest number of three numbers.",max);
return 0;
}
Input & Output:
******Greatest Number Finder******
Enter First number:1
Enter second number:2
Enter Third number:3
3 is the greatest number of three numbers.