Conditional Operator

  


The Conditional Operator in C, also called a Ternary operator, is one of the Operators, which used in the decision-making process, we use a conditional operator to reduce the line of codes. We can use a conditional operator to replace the if-else condition. The basic syntax of a Ternary Operator is given below: 

 

Syntax   

(condition) ? Expression1: Expression2;   

  

To be more clear you can see here:-  

(condition)? True: False; 

 

Flowchart 

 

 

Program 

QUESTION:- write a conditional program to print the greatest value from user input.  


#include <stdio.h> 
#include <conio.h> 
void main() 
    int abc
    printf("enter a value of a:  "); 
    scanf("%d", &a); 
    printf("enter a value of b: "); 
    scanf("%d", &b); 
    c = (a>b)? ab
    printf("The greatest value is %d"c); 
    getch(); 

      Output 

Enter a value of a: 7 

Enter a value of b: 10 

The greatest value is 10 


Follow our page for regular updates.

0 Comments