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:

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

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

3. how to write using the header file iostream only?

4. how to write using pl sql

5. atleast rply....

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

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

8. boss where u post d replies??

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

10. #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();
}

11. #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);
}

12. v.good !

13. 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

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

15. This comment has been removed by the author.

16. #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);
}

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

18. 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;
}

19. 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;
}

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

2. thank yu dear it was helpful

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

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