C, C++ Program to Find Largest of Three Numbers |

To solve this problem, first let's write an algorithm to find largest number among three numbers.

**Algorithm to Find Largest of three Numbers**

1. Declare three variable a ,b, c.

2. Compare a with b and c. If a is greater than b and c than a is greatest among three numbers.

3. Compare b with a and c. if b is greater than a and c than b is greatest among three numbers.

4. Compare c with a and b. If c is greater than a and b than c is greatest among three numbers.

Program to find second largest element in an array

Find largest element in an array

## C Program to Find Largest of three Numbers

#include <stdio.h> int main(){ int a, b, c; printf("Enter three numbers: "); scanf("%d %d %d", &a, &b, &c); if(a >= b && a >= c){ printf("Largest number is %d", a); }else if(b >= a && b >= c){ printf("Largest number is %d", b); }else if(c >= a && c >= b){ printf("Largest number is %d", c); } return 0; }

**Output**-

Enter three numbers :

14

34

23

Largest number is : 34

## Find Largest of three Numbers using Ternary Operator

#include <stdio.h> int main(void) { int a, b, c, larg; printf("Enter three numbers \n"); scanf("%d %d %d", &a , &b , &c); larg = (a > b && a > c) ? a : b > c ? b : c ; printf("Largest number is %d ", larg); return 0; }

## C++ Program Find Largest of three Numbers

#include <iostream> using namespace std; int main() { int a, b, c; cout << "Enter three numbers \n"; /* Taking input */ cin >> a >> b >> c; /* If a is greater than b and c. */ if (a > b && a > c) { cout << "Largest number is " << a; /* If b is greater than a and c */ } else if (b > a && b > c) { cout << "Largest number is " << b; } else { cout << "Largest number is "<< c; } return 0; }

Programming question on Arrays

Programming question on Linked List

Sorting algorithm and their time complexity

Stack implementation

Programming questions using Recursion

C, C++ interview questions

Programming Books

## No comments:

## Post a Comment