Here we will understand how to find the largest number among the three numbers using C++ code.
Examples: Input: int a = 5, b = 8, c = 2 Output: The Biggest number among the three is 8 Input: int a = 54, b = 21, c = 9 Output: The Biggest number among the three is 54
- Using if statement.
- Using if-else statement.
- Using Ternary Operator.
- Take three input variables from the user and store them in three different variables a, b, and c.
- Check condition if a >= b and a >= c, if both conditions are true then print "The Biggest number among three is a.
- Check condition if b >= a and b >= c, if both conditions are true then print "The Biggest number among three is b.
- Check condition if c >= a and c >= b, if both conditions are true then print "The Biggest number among three is c.
- Stop the Program.
//C++ Code to find Biggest among three numbers #include<iostream> using namespace std; int main(){ int a, b, c; cout << "Enter three numbers: "; cin >> a >> b >> c; if(a >= b && a >= c) cout<<"The Biggest number among the three is "<<a; if(b >= a && b >= c) cout<<"The Biggest number among the three is "<<b; if(c >= a && c >= b) cout<<"The Biggest number among the three is "<<c; return 0; }
Enter three numbers: 10 34 54 The Biggest number among the three is 54
- Take three input variables from the user and store them in three different variables a, b, and c.
- Check first if-condition, a >= b and a >= c, if conditions are true then print "The Biggest number among three is a" and end the program.
- Check the next else-if condition b >= a and b >= c, if conditions are true then print "The Biggest number among three is b" and end the program.
- If both the above conditions fail then without checking any further conditions you can declare the third variable as the largest variable.
- End the Program.
//C++ Code to find Biggest among three numbers//using if-else #include<iostream> using namespace std; int main(){ int a, b, c; cout << "Enter three numbers: "; cin >> a >> b >> c; if(a >= b && a >= c) cout<<"The Biggest number among the three is "<<a; else if(b >= a && b >= c) cout<<"The Biggest number among the three is "<<b; else cout<<"The Biggest number among the three is "<<c; return 0; }
Enter three numbers: -5 4 5 The Biggest number among the three is 5
- (condition) ? expression 1 : expression 2
//C++ Code to find Biggest among three numbers //using ternary operator #include<iostream> using namespace std; int main(){ int a, b, c; int ans; cout << "Enter three numbers: "; cin >> a >> b >> c; //Ternary Operator ans = (a >= b ? (a >= c ? a : c) : (b >= c ? b : c)); cout<<"The Biggest number among the three is "<<ans; return 0; }
Enter three numbers: 5 3 12 The Biggest number among the three is 12


Trends is an amazing magazine Blogger theme that is easy to customize and change to fit your needs.