Advertisement
Stancu

Probleme de tip semafor

Feb 15th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.27 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6.     int n;
  7.     cin >> n;
  8.  
  9.     switch (n)
  10.     {
  11.  
  12.  
  13.     case 1:
  14.  
  15.         int  cresc, c1, c2 ;
  16.         c1 = 10; cresc = 1;
  17.         cout << "n= "; cin >> n;
  18.         while (n != 0 && cresc == 1)
  19.         {
  20.             c2 = n % 10;
  21.             if (c1 < c2) cresc = 0;
  22.             n /= 10;
  23.             c1 = c2;
  24.         }
  25.         if (cresc == 1) cout << "Cifrele numarului sunt in ordine crescatoare." << endl;
  26.         else cout << "Cifrele numarului nu sunt in ordine crescatoare." << endl;
  27.         break;
  28.  
  29.  
  30.     case 2:
  31.  
  32.         int ci;
  33.         ci = 1;
  34.         cout << "n= "; cin >> n;
  35.         c2 = n % 10;
  36.         while (n != 0 && ci == 1)
  37.         {
  38.             c1 = n % 10;
  39.             if (c1 != c2) ci = 0;
  40.             n /= 10;
  41.             c1 = c2;
  42.         }
  43.         if (ci == 1) cout << "Numarul are toate cifrele identice." << endl;
  44.         else cout << "Numarul nu are toate cifrele identice." << endl;
  45.         break;
  46.  
  47.  
  48.     case 3:
  49.  
  50.         int a, b, des; des = 1;
  51.         cout << "n= "; cin >> n;
  52.         cout << "Intrd. o valoare: "; cin >> a;
  53.         for (int i = 2; i <= n && des == 1; i++)
  54.         {
  55.             cout << "Intrd. o valoare: "; cin >> b;
  56.             if (b > a) des = 0;
  57.             a = b;
  58.         }
  59.         if (des == 1) cout << "Valorile sunt in ordine descrescatoare." << endl;
  60.         else cout << "Valorile nu sunt in ordine descrescatoare." << endl;
  61.         break;
  62.  
  63.     default:
  64.         cout << "Problema nu exista." << endl;
  65.     }
  66.  
  67.  
  68.     return 0;
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement