Advertisement
STANAANDREY

pb5 24/2/2020

Feb 24th, 2020
316
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.48 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. void numere(int n, int v[], int& suma)
  5. {
  6.     suma = 0;
  7.     for (int i = 0; i < n; i++)
  8.     {
  9.         int c = v[i], s = 0;
  10.         while (c > 9)
  11.         {
  12.             s += c % 10;
  13.             c /= 10;
  14.         }
  15.         if (c == s)
  16.             suma += v[i];
  17.     }
  18.     if (!suma)
  19.         suma = -1;
  20. }
  21.  
  22. int main()
  23. {
  24.     int suma, n = 5, v[] = {125,624,44,2110,23};
  25.     numere(n, v, suma);
  26.     cout << suma;
  27.     return 0;
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement