Advertisement
daniil_mironoff

nadezhda

Nov 3rd, 2019
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.53 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. const int SIZE = 10;
  6.  
  7.  
  8. int main() {
  9.     int arr[SIZE];
  10.     for (int i = 0; SIZE > i; i++) {
  11.         cout << "Enter " << i << " number: ";
  12.         cin >> arr[i];
  13.     }
  14.  
  15.     int serSum;
  16.     cout << "Enter search sum: ";
  17.     cin >> serSum;
  18.  
  19.     cout << "Result:";
  20.  
  21.     for (int i = 0; SIZE > i; i++) {
  22.         int num = arr[i];
  23.         int curSum = 0;
  24.  
  25.         while(num != 0) {
  26.             curSum += num % 10;
  27.             num /= 10;
  28.         }
  29.  
  30.         if (curSum == serSum) {
  31.             cout << " " << arr[i];
  32.         }
  33.  
  34.     }
  35.  
  36.    
  37.  
  38.     cout << endl;
  39.  
  40.     return 0;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement