Advertisement
ioana_martin98

Untitled

Dec 20th, 2020
620
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.21 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5.  
  6.     /* Se citeste un sir de numere naturale.
  7.     Se cere sa se determine numarul de numere divizibile cu 5, numarul de numere divizibile cu 2 si numarul de
  8.     numere divizibile cu 10
  9.     ex.n = 7 si 14  5  8  20  6  25  49 = > 3    4    1
  10.     */
  11.  
  12.     /*unsigned int n, x, i, nr5, nr2, nr10;
  13.     nr5 = 0;
  14.     nr2 = 0;
  15.     nr10 = 0;
  16.     cin >> n;
  17.     for (i = 1; i <= n; i++)
  18.     {
  19.         cout <<"i="<< i << ' ';
  20.         cin >> x;
  21.         cout << "x=" << x<<' ';
  22.         if (x % 5 == 0)
  23.         {
  24.             nr5 = nr5 + 1;
  25.             cout << "nr5=" << nr5 << ' ';
  26.         }
  27.         if (x % 2 == 0)
  28.         {
  29.             nr2 = nr2 + 1;
  30.             cout << "nr2=" << nr2 << ' ';
  31.         }
  32.         if (x % 10 == 0)
  33.         {
  34.             nr10 = nr10 + 1;
  35.             cout << "nr10=" << nr10 << ' ';
  36.         }
  37.         cout << endl;
  38.            
  39.     }*/
  40.  
  41.     //cout << nr5 << ' ' << nr2 << ' ' << nr10;
  42.    
  43.     /*2. Se citeste un numar natural x. Sa se afiseze numarul sau de divizori
  44. ex. n=35 => 4*/
  45.     /*unsigned int x, k,i;
  46.     k = 0;
  47.     cout << "k="<<k;
  48.     cin >> x;
  49.     for (i = 1; i <= x; i++)
  50.     {
  51.         cout << "i=" << i << ' ';
  52.         if (x%i == 0)
  53.         {
  54.             k = k + 1;
  55.             cout << "k=" << k;
  56.         }
  57.         cout << endl;
  58.     }
  59.         */
  60.     //cout << k;
  61.     /*3. Se citeste un sir de numere. Sa se afiseze toate numerele care au exact 3 divizori
  62. ex. n=5 si 10  12   9  35  50  => 9*/
  63.     //unsigned int n, x, i, k, d;
  64.     //cin >> n;
  65.     //for (i = 1; i <= n; i++)
  66.     //{
  67.     //  cin >> x;
  68.     //  cout << "x=" << x;
  69.     //  k = 0;
  70.     //  cout << "k=" << k;
  71.     //  for (d = 1; d <= x; d++)//d=1,x
  72.     //  {
  73.     //      cout << "d=" << d << ' ';
  74.     //      if (x%d == 0)
  75.     //      {
  76.     //          k = k + 1;
  77.     //          cout << "k=" << k << endl;
  78.     //      }
  79.     //  }
  80.     //     
  81.     //  if (k == 3)
  82.     //      cout << x << ' ';
  83.     //}
  84.  
  85.     /*4. Se citesc doua numere naturale a si b (a<=b).
  86.     Sa se afiseze descrescator toate numerele din intervalul [a,b]
  87. ex. a=4, b=7 =>7  6  5  4*/
  88.     //unsigned int a, b, i;
  89.     //cin >> a;
  90.     //cin >> b;
  91.     //for (i = b; i >= a; i--) {
  92.     //  cout << i << ' ';
  93.     //}
  94.     /*
  95. pentru i=b,a,-1
  96. scrie i
  97.     */
  98.     /*5. Se citeste un sir de n numere naturale. Sa se afiseze valoarea maxima din sir
  99. ex. n=7 si  6  4  5  9  23  18  4 => 23*/
  100.     unsigned int n, x, i, max;
  101.     cin >> n;
  102.     max = 0;
  103.     for (i = 1; i <= n; i++)
  104.     {
  105.         cin >> x;
  106.         if (x > max)
  107.         {
  108.             max = x;
  109.         }
  110.     }
  111.     cout << "max=" << max;
  112.     return 0;
  113. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement