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





16 comments:

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

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

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

    ReplyDelete
  4. how to write using pl sql

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

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

    ReplyDelete
  7. boss where u post d replies??

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

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

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

    ReplyDelete
  11. 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

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

    ReplyDelete
  13. This comment has been removed by the author.

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

    ReplyDelete