---
# System prepended metadata

title: C++(3)

---

![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;
```
![](https://i.imgur.com/D0LkJwn.png)


### 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;
}
```
![](https://i.imgur.com/fAUb5dJ.png)


### 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;
}
```
![](https://i.imgur.com/9g3554h.png)

### 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;
}
```
![](https://i.imgur.com/k5vIRD9.png)


### 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;
}
```
![](https://i.imgur.com/xvV8SkX.png)



### 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;
}
