Write a program to find the largest number among 3 numbers with the ternary operator in C language.

Tested on: Turbo C++ Version 4.0Time Complexity: O (1)Space Complexity: O (1)Open Source: MIT
1
2
3
    #include<stdio.h>
4
5
    int main()
6
    {
7
    	int num1,num2,num3,max;
8
    	printf("Enter three Numbers\n");
9
    	scanf("%d%d%d",&num1,&num2,&num3);
10
    	max=(num1>num2)? num1:num2;
11
    	max=(num3>max)? num3:max;
12
    	printf("The Greatest Number is %d",max);
13
    	return(0);
14
    }
15
16
        

Output

1
2
    Enter three Numbers
3
    5
4
    14
5
    8
6
    The Greatest Number is 14
7
        

Rate the Code

Reviews are published after a quick safety check (usually within 24 hours).

Reviews are public. Developers can see basic device specifications to respond. Learn more

How to run largest number among 3 numbers with the ternary operator program in C-Language?

To run largest number among 3 numbers with the ternary operator program in C-Language, follow the below mentioned steps:

  1. Copy the Code: Press the copy button in the code block to copy the complete code.
  2. Open Turbo C++ Version 4: Open the Turbo C++ (Version 4) software on your system.
  3. Paste the code: Paste the copied code into Turbo C++’s editor.
  4. Compile the Code: Compile the program by pressing the Alt+F9 keys. This shows you the errors and warnings, if any.
  5. Run the code: Press the Ctrl+F9 keys to run the program if the program is successfully compiled.
  6. Enter the Input: Provide the required inputs or your desired inputs, if applicable.
  7. Receive the Result: Get the result of the program on the screen based on the provided inputs.

More about the Greatest Number program in C language

Aim: To find out the greatest number out of three numbers provided by the user as input.

Concepts used in this program

  • The ternary operator (?) is used in this program. The ternary operation is a conditional operator that executes one value based on the basis of condition.

Real-life example

  1. Data Processing Software: To find out the greatest value of a dataset.
  2. Operating System Scheduling: To compare processes based on priority.
  3. Improve Logic Building: This program helps to improve the logic-building of the students.
License: This program's source code is open-sourced under the MIT License, while the rest of the program's text content and overall dhimanp platform and brand content remain proprietary under dhimanp.

Submit your modified code

Your submissions are published after a quick safety check (usually within 7 days).

Submissions are public. Developers can see basic device specifications to respond. Learn more

Disclaimer

The information that you shared with us will be publicly visible, and everyone can see your information. And we (dhimanp) are not responsible if anyone misuses this information. We can remove any submitted code at any time for better transparency.

Privacy Policy

If you share your data with us by submitting your code for credit, then we may show your full name, school or college name, and city name on our website.

We are not using this data to track you and are not selling this data to anyone.

If you want to remove your name from our website, you can contact us, and we will remove your name from our website. In the removal process, full credit, including your full name, school or college, city, and code, will be removed from our website.