Advertisement
Five_NT

Multipli ai lui k, ultima cifra k.

Sep 28th, 2014
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.91 KB | None | 0 0
  1. Scrieti definitia completa a subprogramului care are 3 parametri(a = tablou, n = dimensiunea, k = numar natural < 9).
  2. Subprogramul returneaza nr de elemente din tablou care sunt miltipli ai nr k si au ultima cifra k.
  3. /***********************************************************
  4. Exemplu:
  5. n = 6;
  6. a = (9, 273, 63, 83, 93, 123);
  7. k = 3;
  8. Subprogramul v-a returna valoarea 4.(273, 63, 93, 123)
  9. ***********************************************************/
  10.  
  11. #include <iostream>
  12.  
  13. using namespace std;
  14.  
  15. int a[100], n, k;
  16. void prog(int a[100], int n, int k)
  17. {
  18.     int nr = 0;
  19.     for(int i = 1; i <= n; i ++)
  20.         if(a[i] % k == 0 && a[i] % 10 == k)
  21.                 nr++;
  22.     cout << nr;
  23. }
  24. int main()
  25. {
  26.     cout << " n = "; cin >> n;
  27.     cout << " k = "; cin >> k;
  28.     for(int i = 1; i <= n; i ++)
  29.     {
  30.         cout << "a[" << i << "]= ";
  31.         cin >> a[i];
  32.     }
  33.     prog(a, n, k);
  34.     return 0;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement