# Find greatest between three numbers using function

This article illustrates the concept how to find greatest between three numbers using function in c/c++. Here is the source code and output of both the programs.

## C Programming language

#### Program

``````
#include<stdio.h>
#include<conio.h>
int larger(int,int,int);
void main()
{
int first,second,third,larg;
clrscr();
printf("Enter first number:- ");
scanf("%d",&first);
printf("Enter second number:- ");
scanf("%d",&second);
printf("Enter third number:- ");
scanf("%d",&third);
larg=larger(first,second,third);
printf("Largest of three numbers is:- %d",larg);
getch();
}
int larger(int x,int y,int z)
{
if(x>y)
{
if(x>z)
{
return x;
}else{
return z;
}
}else{
if(y>z)
{
return y;
}else{
return z;
}
}
}
``````

#### After successfully compiling and executing the above C program,output is:- ## C++ Programming language

#### Program

``````
#include<iostream.h>
#include<conio.h>
int larger(int,int,int);
void main()
{
clrscr();
int first,second,third,larg;
cout<<"Enter first number:- ";
cin>>first;
cout<<"Enter second number:- ";
cin>>second;
cout<<"Enter third number:- ";
cin>>third;
larg=larger(first,second,third);
cout<<"Largest of three numbers is:- "<<larg;
getch();
}
int larger(int x,int y,int z)
{
if(x>y)
{
if(x>z)
{
return x;
}else{
return z;
}
}else{
if(y>z)
{
return y;
}else{
return z;
}
}
}
``````

#### After successfully compiling and executing the above C++ program,output is:- #### About article

Written By:- Admin

Published on:- 03/25/2018

Published By:- Snapcout

Don't forget to share the article if you like it:-