Skip to main content

C PROGRAM: Simple explanation of c program to find greatest of two number using conditional operator.

C Programming


What is operators? What is conditional operator? How to find greatest of two number using conditional operator? We will be discussing about the c program to find greatest of two number using conditional operator and the other details.

what is operator?

   An operator is a symbolic, which performs particular manipulations or operations on data that is assigned to a variable.
Following are the types of operator:
  1. Arithmetic operators        -   +,-,*,/,%
  2. Relational operators         -   <,>,==,<=,>=,!=
  3. Logical operator               -   &&,||,!=
  4. Increment or Decrement  -    ++,--
  5. Assignment operator        -    =
  6. Bit wise operator             -     &,|,^,>>,<<,~
  7. Comma operator             -     ,
  8. Conditional operator        -     ?:
we are discussing only conditional operator here. 

what is conditional operator?
     A Conditional operator is also called Ternary operator. It is similar to if-else operator but, it takes less space and easy to read than if-else statement.
  
   syntax:
       variable= expression1? expression2: expression3
   
   working :
          expression1 is considered to be the condition, if the condition is true, expression2 is executed and result is found, if the condition is false expression3 is executed and result is found.

 
C program to find greatest of two number using conditional operator.


C program to find greatest of two number using conditional operator.


Explaination:

  • Header file stdio.h standard input and output to get input and show output, conio.h console input and output.
  • void main -  function returning value will be null.
  • intdeclare the type of variable. where 'a' and 'b' variables.
  • clrscr - clear the screen.
  • printf - used to print the output screen.
  • scanf - used to accept input (%d), and read (&n).
  • getch - used to hold the screen until the user gives any type of input.
  • I have used conditional operator.

logic behind the program
 
  • conditional operator has the condition that 'a' should be greater than 'b' (a>b).
  • If the condition is true, then the first expression that is, "a is greater" is printed.
  • If the condition is false then the second expression that is "b is greater" is printed.

Output:

here are some output for the above program.

output of C program to find greatest of two number using conditional operator.


The above program is used to find greatest of two number using conditional operator. It is also an example for conditional operator.


In following days we will discuss more programs in detail. If you like to learn more just follow me regularly. If you have any question to ask mention below in comment. Thank you......

Comments