C Language

May 26, 2023

How to use ternary operator in c language

program to use ternary operator in c language


#include<stdio.h>
int main()
{
    int y,z,max;
    printf("Enter values for y and z : ");
    scanf("%d%d",&y,&z);
    max = z>y ? y : z;
    printf("larger of %d and %d is %d\n",y,z,max);
    return 0;
}

output


Enter a values for y and z : 12
4
larger of 12 and 4 is 12

Steps Description

  1. Declare integer three variable y , z and max
  2. printf inbuild function to display value of variable y and z with respective decimal placeholder %d
  3. Evaluation of variable y and z to determine greater than z
  4. Assign max variable with greater than variable y
  5. printf inbuild function to display larger value of variable y

by : Ajaj Khan

Quick Summary:

इस program मैं ternary operator सहायता से large नंबर निकल रहा है