Advertisement
ioana_martin98

Untitled

May 8th, 2022
799
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.57 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4. /*
  5. 7. Se citeste un numar natural n. Sa se construiasca un vector cu n elemente care contine pe pozitii pare numere
  6. naturale nenule divizibile cu 5 , in ordine crescatoare, iar pe pozitii impare valoarea 0.(indexare de la 0)
  7. Ex, n=11 =&gt; v=(5,0,10,0,15,0,20,0,25,0)
  8. */
  9.  
  10. int main()
  11. {
  12.     int n, i, j, v[100001], ok, x=5;
  13.     cin >> n;
  14.     for (i = 0; i < n; i++)
  15.     {
  16.         if (i % 2 == 0)
  17.         {
  18.             v[i] = x;
  19.             x += 5;
  20.         }
  21.         if (i % 2 == 1)
  22.         {
  23.             v[i] = 0;
  24.         }
  25.     }
  26.     for (i = 0; i < n; i++)
  27.         cout << v[i]<< " ";
  28.     return 0;
  29. }
  30.  
  31.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement