greatest and smallest in 3 numbers cpp

#include <iostream>
using namespace std;

int main() {
    int num1, num2, num3;

    cout << "Enter three numbers: ";
    cin >> num1 >> num2 >> num3;

    int greatest = (num1 > num2) ? ((num1 > num3) ? num1 : num3) : ((num2 > num3) ? num2 : num3);
    int smallest = (num1 < num2) ? ((num1 < num3) ? num1 : num3) : ((num2 < num3) ? num2 : num3);

    cout << "The greatest number is: " << greatest << endl;
    cout << "The smallest number is: " << smallest << endl;

    return 0;
}

This C++ code snippet prompts the user to input three numbers. It then compares these numbers to find the greatest and smallest among them using nested ternary operators. Finally, it displays the greatest and smallest numbers to the user.