Related Posts Plugin for WordPress, Blogger...

About

Follow Us

Thursday, 12 February 2015

Introduction: 

Now in this article i will explain how to find greater between 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.

#include<conio.h>
       #include<stdio.h>
       main()
       {
             int x,y,large;
             printf("Enter first value: ");
             scanf("%d",&x);
             printf("Enter second value: ");
             scanf("%d",&y);
            large=(x>y)?x:y;
            printf("Largest value among two numbers=%d",large);
            getch();
             }
Now run the program using Ctrl+F9


Output:

Enter first value: 16
Enter second value: 10
Largest value among two numbers=16
Categories: ,

0 comments:

Post a Comment