Write a C Program to Find Larger Number Between Two Numbers using Conditional Operator

January 12, 2023 0 Comments

In this tutorial learn how you can find the larger number between two numbers using a conditional operator. We are using a test case “<test case>? True value: false value”. 

This is the shortcut form of the if statement. First, write a statement and use “?” as a separator then the first one is a true case and else or false case which is separated by “:”.

C programming is a powerful general-purpose programming language. It can be used to develop software like operating systems, databases, compilers, etc.

Write a Program to Find Larger Number Between Two Numbers using Conditional Operator

Here is the code to find the larger number between two numbers using a conditional operator in C programming.

#include <stdio.h> //WAP to find the larger number between two numbers using conditional operator. <test case>? True value: false value
int main(){
    int a,b;
    printf("Please enter two numbers:\n");
    scanf("%d%d",&a,&b);
    (a>b)?printf("%d is greater.",a):printf("%d is greater.",b);
    return 0;
}

Test Live At Jdoodle

Conclusion

This is how you can find the larger number between two numbers using a conditional operator in c programming. Comment below if you like our tutorial.

Leave a comment

Gallery