Conditional Operator

#include<stdio.h>
#include<conio.h>
main()
{
int a,b,x;
a=10;
b=15;
x=(a>b)? a:b ;
getch();
}
----------------------------------
if (a> b)
x=a;
else
x=b; 

3 comments:

  1. //Write a C Program by using Conditional Operator

    #include
    main()
    {
    int a,b;
    scanf("%d%d",&a,&b);

    ( a > b) ?

    printf("A is greater")
    :
    printf("B is greater");

    }

    ReplyDelete
  2. #include
    main()
    {
    int a,b;
    scanf("%d%d",&a,&b);

    ( a < b) ?

    printf("b is greater")
    else
    printf("a is greater");

    }

    ReplyDelete
  3. #include
    main()
    {
    int a,b;
    scanf("%d%d",&a,&b);

    ( a < b) ?

    printf("b is greater")
    else
    printf("a is greater");

    }

    ReplyDelete