STANAANDREY

sb prog 12

Feb 24th, 2022 (edited)
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.37 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. using namespace std;
  4. ofstream fout("trei.out");
  5.  
  6. int getSum(int x) {
  7.     int sum = 0;
  8.     while (x) {
  9.         sum += x % 10;
  10.         x /= 10;
  11.     }
  12.     return sum;
  13. }
  14.  
  15. int main() {
  16.     for (int i = 100; i < 1000; i++) {
  17.         if (i % getSum(i) == 0) {
  18.             fout << i << ' ';
  19.         }
  20.     }
  21.  
  22.     return 0;
  23. }
  24.  
Add Comment
Please, Sign In to add comment