Advertisement
halexandru11

a doua problema

Nov 29th, 2020
75
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. unsigned int suma(unsigned int x)
  6. {
  7.     unsigned int s = 0;
  8.     while(x > 0)
  9.     {
  10.         s = s + x%10;
  11.         x = x/10;
  12.     }
  13.     return s;
  14. }
  15.  
  16. int main()
  17. {
  18.     unsigned int n, a[100];
  19.     cin >> n;
  20.     for(int i = 0; i < n; ++i)
  21.     {
  22.         cin >> a[i];
  23.     }
  24.  
  25.     unsigned int d3 = 0, d5 = 0, cnt = 0;
  26.     for(int i = 0; i < n; ++i)
  27.     {
  28.         if(a[i]%3 == 0)
  29.         {
  30.             d3++;
  31.         }
  32.         if(a[i]%5 == 0)
  33.         {
  34.             d5++;
  35.         }
  36.         if(suma(a[i])%2 == 0) {
  37.             cnt++;
  38.         }
  39.     }
  40.     cout << d3 << " " << d5 << " " << cnt;
  41.     return 0;
  42. }
  43.  
Advertisement
RAW Paste Data Copied
Advertisement