Tuesday, 11 September 2012

Write a program to find the greatest of the three numbers entered through the keyboard using conditional operators.


main()
{
 int n1,n2,n3,num;
 printf("Enter any three numbers :- \n");
 scanf("%d%d%d",&n1,&n2,&n3);
 num = (n1>n2) && (n1>n3)?n1:(n2>n1) &&  (n2>n3)?n2:n3;
 printf("%d is the greatest number among all.",num);
}

output:-

1 comment:

  1. This is my Programme in Java=====



    public class GretestThree {

    public static void main(String[] args)
    {
    int no1 = 5;
    int no2 = 2;
    int no3 = 8;

    if(no1>=no2&&no1>=no3)
    {
    System.out.println("No1 is Greatest");
    }

    else if (no2>=no1&&no2>=no3)
    {
    System.out.println("No2 is Greatest");
    }

    else
    {
    System.out.println("No3 is greatest: "+no3);
    }

    }
    }

    ReplyDelete