Please disable your adblock and script blockers to view this page

How to find greatest of two numbers using conditional operator in C Language

Introduction: In previous article i explained how to Find greatest of three numbers using nested if else statement in C Language and How to swap two numbers without using temporary variable in C Language? and Check whether a number is positive or negative using if else in C Language and Check whether a number is even or odd using if else statement in C Language. Now in this article i will explain how to find greatest of two numbers using conditional operator in C Language. Conditional operator is also known as ternary operator and its symbol is ?:
 The syntax for conditional operator is: condition?expression1:expression2;
Condition is evaluated either true or false as a Boolean expression . If condition is true expression1 will be evaluated and become the result else expression2 will be evaluated and become the result.Let's create a program to understand the working of ternary operator.

             int x,y,large;
             printf("Enter first value: ");
             printf("Enter second value: ");
            printf("Largest value among two numbers=%d",large);
Now run the program using Ctrl+F9

Enter first value: 56
Enter second value: 90
Largest value among two numbers=90

Next Post »

If you have any question about any post, Feel free to ask.You can simply drop a comment below post or contact via Contact Us form. Your feedback and suggestions will be highly appreciated. Also try to leave comments from your account not from the anonymous account so that i can respond to you easily.. ConversionConversion EmoticonEmoticon