Write a program is the conditional opreator in the C program?
Conditional operator also known is ternary operator.
Conditional operator syntex is :
(condition) ? true statement : false statement
for example :
int a =5, int=7
(condition) ? true statement : false statement
(a>b) ? print first : if not then print second
/* hi friend today learn about the conditional operator used in C program */
#include<stdio.h>
main()
{ int a,b;
printf("your two positive no is : %d & %d \n",a,b,scanf("%d%d",&a,&b));
//scanf("%d%d",&a,&b);
(a>b) ?printf(" your %d is the greater than %d ",a,b):printf("your %d no is the greater than %d",b,a);
}
OUTPUT:
6 7
your two positive no is : 6 & 7
your 7 no is the greater than 6
No comments:
Post a Comment