Advertisement
Dani_info

variabile semafor

Feb 15th, 2018
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.90 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.     int pb;
  8.     cout<<"Introdu nr problemei: "; cin>>pb;
  9.     switch(pb)
  10.     {
  11.     case 1:
  12.         {
  13.             //Se citește un număr natural, n. Să se verifice dacă numărul are cifrele în ordine crescătoare.
  14.             int n, ok=1;
  15.             cout<<"n="; cin>>n;
  16.             int uc=n%10;
  17.             n/=10;
  18.             do
  19.             {
  20.                 if(n%10>uc)
  21.                     ok=0;
  22.                 uc=n%10;
  23.                 n/=10;
  24.             }
  25.             while(n!=0 && ok==1);
  26.             if(ok)
  27.                 cout<<"DA"<<endl;
  28.             else
  29.                 cout<<"NU"<<endl;
  30.             break;
  31.         }
  32.     case 2:
  33.         {
  34.             //Se citește un număr natural, n. Să se verifice dacă numărul are toate cifrele identice.
  35.             int n, ok=1;
  36.             cout<<"Introdu nr: "; cin>>n;
  37.             int uc=n%10;
  38.             for(int i=n/=10; i>0 && ok==1; i/=10)
  39.             {
  40.                 if(i%10!=uc)
  41.                     ok=0;
  42.             }
  43.             if(ok)
  44.                 cout<<"DA"<<endl;
  45.             else
  46.                 cout<<"NU"<<endl;
  47.             break;
  48.         }
  49.     case 3:
  50.         {
  51.             //Se citeste un număr natural, n, și apoi un șir de n numere naturale. Să se verifice dacă valorile citite sunt în ordine descrescătoare.
  52.             int n, ok=1, x, y;
  53.             cout<<"Cate nr se cotesc??"; cin>>n;
  54.             cout<<"Introdu nr: "; cin>>x;
  55.             for(int i=1; i<n && ok==1; i++)
  56.             {
  57.                 cout<<"Introdu nr: "; cin>>y;
  58.                 if(y>x)
  59.                     ok=0;
  60.                 x=y;
  61.             }
  62.             if(ok)
  63.                 cout<<"DA"<<endl;
  64.             else
  65.                 cout<<"NU"<<endl;
  66.             break;
  67.         }
  68.         default: cout<<"Aceasta problema nu exista!!!"<<endl;
  69.     }
  70.     return 0;
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement