Skip to content

Instantly share code, notes, and snippets.

@DanielDe
Created October 15, 2012 06:34
Show Gist options
  • Select an option

  • Save DanielDe/3891085 to your computer and use it in GitHub Desktop.

Select an option

Save DanielDe/3891085 to your computer and use it in GitHub Desktop.
CS 10 SI Classroom Session 3 - if statement example
#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