Write a C C++ program to find greatest in three numbers

Write a C C++ program to find greatest in three numbers

C के विभिन्न control statements को जानने के लिए देखें— Control statements in C

If statement और decision making statements के बारे में अधिक जानने के लिए देखें— If statements in C

C program to find greatest in three numbers

#include<stdio.h>
int main()
{
int n1,n2,n3;
printf("Enter three numbers: ");
scanf("%d%d%d",&n1,&n2,&n3);
if(n1>n2)
{
if(n1>n3)
printf("Greatest number = %d",n1);
else
printf("Greatest number = %d",n3);
}
else
{
if(n2>n3)
printf("Greatest number = %d",n2);
else
printf("Greatest number = %d",n3);
}
return 0;
}

C++ program to find greatest in three numbers

#include<iostream>
using namespace std;
int main()
{
int n1,n2,n3;
cout<<"Enter three numbers: ";
cin>>n1>>n2>>n3;
if(n1>n2)
{
if(n1>n3)
cout<<"Greatest number = "<<n1;
else
cout<<"Greatest number = "<<n3;
}
else
{
if(n2>n3)
cout<<"Greatest number = "<<n2;
else
cout<<"Greatest number = "<<n3;
}
return 0;
}

Output of C C++ program to find greatest in three numbers

Enter three numbers: 4 8 5
Greatest number = 8
Enter three numbers: 33 12 15
Greatest number = 33
Enter three numbers: 40 40 40
Greatest number = 40

List of programs based on if statement and other control statements

Share it to: 