Write a C program to find largest of three numbers using ternary operator. Given three input numbers, we have to write a code to find largest of three numbers using ternary operator.
Algorithm to Find Largest of three Numbers using Ternary Operator
1. In first step, let's declare three variables to hold the values of three input numbers.
2. use ternary operator to compare the values of three variable and assign the result into a variable
3. print the value of a variable.
C interview questions
Let's write a program to print the largest among three numbers using ternary operator.
Output :
Enter three numbers : 8 2 1
Largest of three numbers is 8
Program to find second largest element in an array
Find largest element in an array
Find sum of fibonacci series in c, c++
2. use ternary operator to compare the values of three variable and assign the result into a variable
3. print the value of a variable.
C interview questions
C Program to Find Largest of three Numbers using Ternary Operator
Let's write a program to print the largest among three numbers using ternary operator.
#include <stdio.h> int main(){ int a, b, c; printf("Enter three numbers "); scanf("%d %d %d", &a, &b, &c); int result = ( a > b ) ? (a > c ? a : c) : ( b > c ? b : c); printf(" Largest of three numbers is %d ", result); return 0; }
Output :
Enter three numbers : 8 2 1
Largest of three numbers is 8
Program to find second largest element in an array
Find largest element in an array
Find sum of fibonacci series in c, c++
please give me solution
ReplyDeleten^2 + (n-1)^2 + ......... + 2 + 1 c language