C Program To Find The Largest Number Using Ternary Operator
आज के इस आर्टिकल में हम C Language में Ternary Operator or Conditional operator का उपयोग करते हुवे दिए गए Numbers में से कौन सा नंबर बड़ा है, को बताने वाला एक Program बनाएंगे |
Contents
hide
C Program To Find The Largest Number Among Two Numbers Using Ternary Operator
Algorithm-:
- Program Start
- Declaration of variable
- Enter the number of value
- Check the condition, ternary (conditional) operator.
- Display answer according the condition
- Program End .
Flowchart
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
- C Program to Calculate Simple interest and Compound interest
- C Program To Find The Largest Numbers Using Ternary Operator
- C Program to Check Leap Year
इन्हे भी पढ़े -: