C Program To Find The Largest Number Using Ternary Operator

आज के इस आर्टिकल में हम C Language में Ternary Operator or Conditional operator का उपयोग करते हुवे दिए गए Numbers में से कौन सा नंबर बड़ा है, को बताने वाला एक Program बनाएंगे |

C Program to Find the Largest Numbers using Ternary Operator
C Program to Find the Largest Numbers using Ternary Operator

C Program To Find The Largest Number Among Two Numbers Using Ternary Operator

 Algorithm-:

  1. Program Start
  2. Declaration of variable
  3. Enter the number of value
  4. Check the condition, ternary (conditional) operator.
  5. Display answer according the condition
  6. Program End .

Flowchart

C Program To Find The Largest Number Using Ternary Operator

Program to Find the largest number among two numbers using ternary operator

/* C program to find largest among
   two numbers using ternary operator
*/
#include<stdio.h>
#include<conio.h>
void main()
{
  // Variable declaration
   int a,b,larg;  
   printf("Enter two number\n");
   scanf("%d %d",&a,&b);

  // Largest among a and b
   larg = a>b?a:b;      

 // Print the largest number
   printf("largest number is : %d",larg);  
   getch();
}

Output -:

Enter two number
23
56
largest number is : 56

C Program To Find The Largest Number Among Three Numbers Using Ternary Operator

/* C program to find largest among
   Three numbers using ternary operator
*/
#include<stdio.h>
#include<conio.h>
void main()
{
   int a,b,c,larg;    // Variable declaration
   printf("Enter three number\n");
   scanf("%d %d %d",&a,&b,&c);
   larg = a>b?a>c?a:c:b>c?b:c;       // Largest among a, b and c
   printf("largest number is : %d",larg);  // Print the largest number
   getch();
}

Output -:

Enter three number
201
560
281
largest number is : 560

Program To Find The Largest Number Among Four Numbers Using Ternary Operator

/* C program to find largest among
   Four numbers using ternary operator
*/
#include<stdio.h>
#include<conio.h>
void main()
{
   int a,b,c,d,larg;    // Variable declaration
   printf("Enter four number\n");
   scanf("%d %d %d %d",&a,&b,&c,&d);
   larg = ( (a>b && a>c && a>d) ? a : (b>c && b>d) ? b : (c>d)? c : d );
   printf("largest number is : %d",larg);  // Print the largest number
   getch();
}

Output -:

Enter three number
32
64
71
034
largest number is : 71

C Programming Examples

इन्हे भी पढ़े -:

Jeetu Sahu is A Web Developer | Computer Engineer | Passionate about Coding, Competitive Programming and Blogging

Leave a Comment

Ads Blocker Image Powered by Code Help Pro

Ads Blocker Detected!!!

We have detected that you are using extensions to block ads. Please support us by disabling these ads blocker.