Write a c program to find largest among three numbers using conditional operator






Write a c program to find largest among three numbers using conditional operator


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



If you have any suggestions on above c program to find largest or biggest of 3 numbers, please share us.





18 comments:

  1. Excellent piece of code :) Thanks a lot

    ReplyDelete
  2. Thanks for solving many problem related to any programming problem issue....

    ReplyDelete
  3. #include
    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):(b>c?b:c));
    printf("\nThe biggest number is:%d",big);
    return 0;
    }


    wanaa any help regarding C..jst mail me at
    gotopunit@gmail.com

    ReplyDelete
    Replies
    1. Your solution is wrong the correct expression of line no. 6 will be :

      big = (a>b)?(a>c?a:c):(b>c?b:c);

      Delete
  4. any idea how to do this:


    Write a program that requests 5 numbers from the user then finds the minimum number among all the number.

    Sample Input:
    Enter a number 1: 3
    Enter a number 2: 0
    Enter a number 3: -4
    Enter a number 4: 9
    Enter a number 5: 0

    Sample Output:
    Numbers you had input are: 3 0 -4 9 0
    Minimum number is: -4

    ReplyDelete
  5. #include
    #include
    #define size 5
    void main()
    {
    int no[size],min=0,max=0,i;
    clrscr();
    for(i=0;ino[i])
    {
    min=no[i];
    }
    if(max<no[i])
    {
    max=no[i];
    }
    }
    printf("\n Minimum No is : - %d",min);
    printf("\n Maximum No is : - %d",max);
    getch();
    }

    Note : you can find minimum and maximum number from any number of input number.

    ReplyDelete
  6. void main()
    {
    int no[5],i,min,max;
    clrscr();
    for(i=0;i<5;i++)
    {
    printf("\n Enter %d No : - ",i+1);
    scanf("%d",&no[i]);
    }
    min=max=no[i];
    for(i=0;i<5;i++)
    {
    if(min>no[i])
    min=no[i];
    if(max<no[i])
    max=no[i]
    }
    printf("\n Minimum No is : - %d",min);
    printf("\n Maximum No is : - %d",max);
    getch();
    }

    ReplyDelete
  7. #include
    #include
    int main()
    {
    int a,b,c;
    printf("Enter value of a,b,c\n");
    scanf("%d%d%d",&a,&b,&c);
    if(a>b)
    {
    if(a>c)
    printf("Largest no is\t%d",a);
    else
    printf("Largest no is\t%d",c);
    }
    else
    {
    if(b>c)
    printf("Largest no is\t%d",b);
    else
    printf("Largest no is\t%d",c);
    }
    getch();
    }

    ReplyDelete
    Replies
    1. This code is wrong Try new code .

      Delete
  8. I wanna Calculate Biggest number among 5 integers plz help me


    ReplyDelete
  9. pls explain me the 6th line of the above prog...

    ReplyDelete
  10. 6th line: a>b&&a>c?a:b>c?b:c

    It is equivalent to:
    if(a > b && a>c)
    return a
    else if (b>c)
    return b
    else
    return c

    ReplyDelete
  11. nice explanation

    ReplyDelete
  12. thanks for the help and explanation

    ReplyDelete
  13. Please show me a program which Takes 10 integers as input and prints the largest one.

    ReplyDelete
  14. Write a c program that allows the user to input an integer value n, followed by n floating point numbers and display the sum of these n values as well as the largest and smallest among the values.

    ReplyDelete
  15. then how to find the smallest

    ReplyDelete
  16. biggest of 3 nos program is correct.. got correct output ........ but we enter 8-3-9 getting "3 is a largest no" (or) if we enter this no 6-5-9 also getting "5 is largest no" ......... how is possible pls give a solution for me
    ...............by raghu

    ReplyDelete