desislava_topuzakova

01. Number Pyramid начин 1

Feb 14th, 2021
961
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.03 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.     //четирицифрени числа: 1111 до 9999
  8.     //n = 16
  9.     //2418 -> 2    4    1     8
  10.     //n % всяка една от цифрите = 0
  11.     int n;
  12.     cin >> n;
  13.     for( int number = 1111; number <= 9999; number++)
  14.     {
  15.         //цифрите на числото
  16.         //2417
  17.         int thousands = number / 1000;
  18.         int hundreds = number / 100 % 10; //2417 / 100 = 24 % 10 = 4
  19.         int tens = number / 10 % 10; //2417 / 10 = 241 % 10 = 1
  20.         int units = number % 10;
  21.         //n % thousands == 0
  22.         //n % hundreds == 0
  23.         //n % tens == 0
  24.         //n % units == 0
  25.         bool check1 = thousands != 0 && n % thousands == 0;
  26.         bool check2 = hundreds != 0 && n % hundreds == 0;
  27.         bool check3 = tens != 0 && n % tens == 0;
  28.         bool check4 = units != 0 && n % units == 0;
  29.         if (check1 && check2 && check3 && check4) {
  30.             cout << number << " ";
  31.         }
  32.  
  33.     }
  34.  
  35.  
  36. }
Advertisement
Add Comment
Please, Sign In to add comment