Search

Monday, December 1, 2014
0 comments

Program to find the larger of two numbers using ternary operator

10:31 PMMonday, December 1, 2014
larger = (a>b)? a:b;
The simple logic behind the program is, when a(variable) is greater than b, the value of a is assigned to larger(variable). Otherwise, the value of b is assigned to larger. The program to find the larger of two numbers using ternary operator is shown below:
#include<conio.h>
#include<stdio.h>
void main()
{
int a,b,larger;
clrscr();
printf("Enter a and b:\n");
scanf("%d%d",&a,&b);
/*The larger of a and b is stored in larger*/
larger=(a>b)?a:b;
printf("Larger=%d\n",larger);
getch();
}

Code generate the Following output


Program to find the larger of two numbers using ternary operator

Protected by Copyscape Online Copyright Protection Software

0 comments :

Post a Comment

 
Toggle Footer
Top