Created
October 15, 2012 06:34
-
-
Save DanielDe/3891085 to your computer and use it in GitHub Desktop.
CS 10 SI Classroom Session 3 - if statement example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| using namespace std; | |
| int main() { | |
| // finding the maximum of two numbers | |
| int num1, num2; | |
| cout << "Enter two numbers: "; | |
| cin >> num1 >> num2; | |
| if (num1 > num2) { | |
| cout << num1 << " is the largest number." << endl; | |
| } else { | |
| cout << num2 << " is the largest number." << endl; | |
| } | |
| // finding the maximum of three numbers | |
| int num3; | |
| cout << "Enter three numbers: "; | |
| cin >> num1 >> num2 >> num3; | |
| if (num1 > num2) { | |
| if (num1 > num3) { | |
| cout << num1 << " is the largest number." << endl; | |
| } else { | |
| cout << num3 << " is the largest number." << endl; | |
| } | |
| } else { | |
| if (num2 > num3) { | |
| cout << num2 << " is the largest number." << endl; | |
| } else { | |
| cout << num3 << " is the largest number." << endl; | |
| } | |
| } | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment