fcamuso

Lezione 18a (eserczio if ... else)

Mar 25th, 2026
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.42 KB | None | 0 0
  1. /*  Letti tre numeri interi da tastiera visualizzare il massimo dei tre valori inseriti
  2.  *  Se i numeri sono uguali visualizzare un messaggio che lo segnala.
  3.  */
  4.  
  5. import std;
  6.  
  7. int leggiIntero(std::string messaggio)
  8. {
  9.     int n{ 0 };
  10.     std::print("{}", messaggio);
  11.  
  12.     std::cin >> n;  //nessun controllo per brevitá
  13.     return n;
  14. }
  15.  
  16. auto main() -> int
  17. {
  18.     int a{ 0 }, b{ 0 }, c{ 0 };
  19.     a = leggiIntero("Inserisci il primo numero: ");
  20.     b = leggiIntero("Inserisci il secondo numero: ");
  21.     c = leggiIntero("Inserisci il terzo numero: ");
  22.  
  23.     if (a == b)
  24.     {
  25.         if (a == c)
  26.         {
  27.             std::cout << "i tre  numeri sono uguali" << std::endl;
  28.         }
  29.         else
  30.         {
  31.             if (a > c)
  32.             {
  33.                 std::cout << a << std::endl;
  34.             }
  35.             else
  36.             {
  37.                 std::cout << c << std::endl;
  38.             }
  39.         }
  40.     }
  41.     else
  42.     {
  43.         if (a < b)
  44.         {
  45.             if (b < c)
  46.             {
  47.                 std::cout << c << std::endl;
  48.             }
  49.             else
  50.             {
  51.                 std::cout << b << std::endl;
  52.             }
  53.         }
  54.         else
  55.         {
  56.             if (a > c)
  57.             {
  58.                 std::cout << a << std::endl;
  59.             }
  60.             else
  61.             {
  62.                 std::cout << c << std::endl;
  63.             }
  64.         }
  65.     }
  66.            
  67.     return 0;
  68. }
  69.  
Advertisement
Add Comment
Please, Sign In to add comment