FIND GREATEST AMONG 3 NUMBERS USING CONDITIONAL OPERATOR IN C PROGRAM








Find the greatest number in given three numbers

#include<stdio.h>
int main(){
int a,b,c,big;
printf("\nEnter 3 numbers:");
scanf("%d %d %d",&a,&b,&c);
big=(a>b&&a>c?a:b>c?b:c);
printf("\nThe biggest number is:%d",big);
return 0;
}




C program for largest of 3 numbers
Write a c program to find largest of three numbers


#include<stdio.h>
int main(){
  int a,b,c;
  int big;
   
  printf("Enter any there numbers: "); 
  scanf("%d%d%d",&a,&b,&c);


  if(a>b && a>c)
    big = a;
   else if(b>c)
    big = b;
   else
    big = c;
   
   printf("Largest number is: %d",big); 


  return 0;
}


Sample output:


Enter any there numbers: 13 25 6
Largest number is: 25





23 comments:

shiva said...

how to find biggest of three nnumbers using macros,that is using #define preprocessor.

Yusuf said...

#include
#define max(a,b,c) (a>b&&a>c?a:b>c?b:c)
int main()
{
printf("Enter three numbers:");
scanf("%d %d %d",&a,&b,&c);
printf("Greatest of three number is : %d",max(a,b,c));
return 0;
}

Arpan said...

how to write using the header file iostream only?

javian said...

how to write using pl sql

princess said...

atleast rply....

Anonymous said...

Write a program that accepts five numbers from the user and displays the highest and lowest number. Assume that there are no duplicate values.

Anonymous said...

how can we write the logic of finding d greatest numbers among three in a single if statement..pls suggest

Anonymous said...

boss where u post d replies??

Pravin 44 said...

Hey guys if I want to dis same without ternary operator that to in single if statement plz rply plz

Arpan Ray said...

#include
void main()
{
int a,b,c,l;
clrscr();
printf("Enter three numbers...");
scanf("%d%d%d",&a,&b,&c);
l=a;
if(l<b)
{
l=b;
}
if(l<c)
{
l=c;
}
printf("greatest among given three numbers is %d",l);
getch();
}

Md.Faizul Haque Nayan said...

#include

void main()
{
int a,b,c;
int biggest;

printf("Enter 1st Number: ");
scanf("%d", &a);
printf("Enter 2nd Number: ");
scanf("%d", &b);
printf("Enter 3rd Number: ");
scanf("%d", &c);

if(a > b)
{
if(a > c)
biggest = a;
else
biggest = c;
}
else
{
if(b > c)
biggest = b;
else
biggest = c;
}
printf("Biggest of 3 numbers is: %d\n", biggest);
}

Immu Mirza said...

v.good !

Anonymous said...

please give me an example program that will print the 3 numbers from highest to lowest.
sample output:
Enter first number:5
Enter second number:9
Enter third number:3

9, 5, 3

Sanjay Chandak said...

bt when we write 5
5
4
so ans is 4 bt it is smaller so please check it

Adam said...
This comment has been removed by the author.
Adam said...

#include
void main()
{
int x,y,z,max;
printf("Enter three numbers\n");
scanf("%d%d%d", &x, &y, &z);
if (x>y) max=x;
else max=y;
if (z>max) max=z;
printf("Max = %d\n", max);
}

Micky Syiemlieh said...

#include
int main()
{
float a, b, c;
printf("Enter three numbers: ");
scanf("%f %f %f", &a, &b, &c);
if(a>=b && a>=c)
printf("Largest number = %.2f", a);
if(b>=a && b>=c)
printf("Largest number = %.2f", b);
if(c>=a && c>=b)
printf("Largest number = %.2f", c);
return 0;
}

Unknown said...

in c++ we can use this code
#include
#include
void main()
{clrscr();
int a,b,c,greatest;
cout<<"ENTER THE VALUE FOR A,B,C:";
cin>>a>>b>>c;
greatest=a>b&&a>c?a:(b>c?b:c);
cout<<"the greatest no is="<<greatest;
}

abi said...

can also use this:
void main()
{
int a,b,c,big;
printf("enter 3 numbers:");
scanf("%d %d %d",&a,&b,&c);
big=(a>b)?(a>c)?a:c:(b>c)?b:c;
printf("%d is the biggest number",big);
getch();
return 0;
}

gowsitha said...

Thank you abi.This is very useful to know better about conditional operators.

divya dd said...

thank yu dear it was helpful

ankit chauhan said...

how to use both inline and macros function in program to find largest n three numbers

shivani said...

Guys plz help me to find minimum of 3 numbers using conditional operators