Q25 Write a c program to find the greatest of the three numbers entered through the keyboard. Use conditional operators.

Write a program to find the greatest of the three numbers entered through the keyboard. Use conditional operators.

Program: 93

Write a c program to find the greatest of the three numbers entered through the keyboard. Use conditional operators.

(expression_1 ? expression_2 : expression_3)

#include<stdio.h>
#include<conio.h>
int main()
{
    int x, y, z, max;

    printf("Enter 1st Number: ");
    scanf("%d", &x);
    printf("Enter 2nd Number: ");
    scanf("%d", &y);
    printf("Enter 3rd Number: ");
    scanf("%d", &z);


    /*conditional operator
    variable (for storing value)=(expression1 ? True_block : False_block);
    here expression 1 is a conditional statement
    if expression1 is true than True block will be execute
    otherwise False block will be execute*/

    max = x;

    max = (max<y ? y : max);
    max = (max<z ? z : max);

    printf("Greatest Number is %d", max);

}

Output:

 Enter 1st Number: 100
 Enter 2nd Number: 2104
 Enter 3rd Number: 82
 Greatest Number is 2104

Lokesh Kumar: Being EASTER SCIENCE's founder, Lokesh Kumar wants to share his knowledge and ideas. His motive is "We assist you to choose the best", He believes in different thinking.
Related Post
Leave a Comment

This website uses cookies.