Home »
Code Snippets »
C/C++ Code Snippets
C program to find greatest of three numbers using function.
In this c program we will learn how to find greatest of three number using function in c programming language?
Here is a function largestNumber which will take three integer arguments and returns greatest number from them.
C program - find greatest of three numbers using function
Let’s consider the following program
/*C program to find greatest of three numbers using function*/
#include <stdio.h>
/*function to get largest among three numbers*/
int largestNumber(int a,int b, int c)
{
int largest=0;
if(a>b && a>c)
largest=a;
else if(b>a && b>c)
largest=b;
else
largest=c;
return largest;
}
int main()
{
int a,b,c;
printf("Enter three numbers: ");
scanf("%d%d%d",&a,&b,&c);
printf("Largest number is: %d\n",largestNumber(a,b,c));
return 0;
}
Output
Enter three numbers: 10 20 11
Largest number is: 20