max of three numbers c++ code example

Example 1: max three values c++

int a = 1;
    int b = 2;
    int c = 3;

    int m = std::max({a, b, c});

Example 2: find the biggest number from 3 numbers c++

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

Tags:

Cpp Example