Write a C program to compare two ages using ternary operator.
byNEED WORK PRODUCE WORK-
1
TASK-
Write a c program to find the younger age between two ages. First enter the ages and then find the younger age print by the program using the ternary operator.
TERNARY OPERATOR:
Its same as if -- else condition e.g
BY IF---ELSE;;
if (x>y) z=x; else z=y;
BY TERNARY OPERATOR:
z=x>y ? x : y;//here we can write whole condition in one line.
CODE:
#include<stdio.h>
int main(){
int friend1,friend2,age;
printf("Enter age of friend1 ");//Asking age of 1st friend
scanf("%d",&friend1); //taking input
printf("\nEnter age of friend2 ");//Asking age of 2nd friend
scanf("%d",&friend2); //taking input
age= (friend1<friend2)? friend1: friend2; //Condition using ternary operators
Great and nice
ReplyDelete