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

 

Flowchart

Finding greatest in three numbers flowchart

 

Coding in C

#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;
}

 

Coding in C++

#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

Finding greatest in three numbers output

 

Published by

admin

I am a computer teacher, programmer and web developer