![Uploading file..._69u0y9l0s]() # C++(3) ### Find Largest Number Using if Statement ```cpp= #include <iostream> using namespace std; int main() { float n1, n2, n3; cout << "Enter three numbers: "; cin >> n1 >> n2 >> n3; if(n1 >= n2 && n1 >= n3) cout << "Largest number: " << n1; if(n2 >= n1 && n2 >= n3) cout << "Largest number: " << n2; if(n3 >= n1 && n3 >= n2) cout << "Largest number: " << n3; ```  ### Find Largest Number Using if...else Statement ```cpp= #include <iostream> using namespace std; int main() { float n1, n2, n3; cout << "Enter three numbers: "; cin >> n1 >> n2 >> n3; if((n1 >= n2) && (n1 >= n3)) cout << "Largest number: " << n1; else if ((n2 >= n1) && (n2 >= n3)) cout << "Largest number: " << n2; else cout << "Largest number: " << n3; return 0; } ```  ### Find Largest Number Using Nested if...else statement ```cpp= #include <iostream> using namespace std; int main() { float n1, n2, n3; cout << "Enter three numbers: "; cin >> n1 >> n2 >> n3; if (n1 >= n2) { if (n1 >= n3) cout << "Largest number: " << n1; else cout << "Largest number: " << n3; } else { if (n2 >= n3) cout << "Largest number: " << n2; else cout << "Largest number: " << n3; } return 0; } ```  ### Check Leap Year Using if...else Ladder ```cpp= #include <iostream> using namespace std; int main() { int year; cout << "Enter a year: "; cin >> year; if (year % 400 == 0) { cout << year << " is a leap year."; } else if (year % 100 == 0) { cout << year << " is not a leap year."; } else if (year % 4 == 0) { cout << year << " is a leap year."; } else { cout << year << " is not a leap year."; } return 0; } ```  ### Check Leap Year Using Nested if ```cpp= #include <iostream> using namespace std; int main() { int year; cout << "Enter a year: "; cin >> year; if (year % 4 == 0) { if (year % 100 == 0) { if (year % 400 == 0) { cout << year << " is a leap year."; } else { cout << year << " is not a leap year."; } } else { cout << year << " is a leap year."; } } else { cout << year << " is not a leap year."; } return 0; } ```  ### Check Leap Year Using Logical Operators ```cpp= #include <iostream> using namespace std; int main() { int year; cout << "Enter a year: "; cin >> year; if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) { cout << year << " is a leap year."; } else { cout << year << " is not a leap year."; } return 0; }
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up