Conditional and Ternary operator ( ?, : )
Conditional and Ternary operator is used to check the condition at that place of it by using this operator we can minimize the length of the program because true part and false part of condition is written in a single line.
Syntax
(condition )? true part : false part
Examples:--
/*Program to find the largest no among two number using conditional and ternary operator */
#include<stdio.h>
#include<conio.h>
main()
{ int a,b;
clrscr();
printf(" \n Enter the value for a and b = \n");
scanf("%d%d",&a,&b);
(a>b)?printf("%d is largest ",a) : printf("%d is largest ",b);
getch();
}
/* Output:--
Enter the value for a and b =20
10
20 is largest
*/
flowchart :--
💬ðŸ’😀👇
No comments:
Post a Comment
This Blog helps you to learn basics to high level programming coding and practicals.
conceptual understanding