Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using namespace std;
- int main()
- {
- //четирицифрени числа: 1111 до 9999
- //n = 16
- //2418 -> 2 4 1 8
- //n % всяка една от цифрите = 0
- int n;
- cin >> n;
- for( int number = 1111; number <= 9999; number++)
- {
- //цифрите на числото
- //2417
- int thousands = number / 1000;
- int hundreds = number / 100 % 10; //2417 / 100 = 24 % 10 = 4
- int tens = number / 10 % 10; //2417 / 10 = 241 % 10 = 1
- int units = number % 10;
- //n % thousands == 0
- //n % hundreds == 0
- //n % tens == 0
- //n % units == 0
- bool check1 = thousands != 0 && n % thousands == 0;
- bool check2 = hundreds != 0 && n % hundreds == 0;
- bool check3 = tens != 0 && n % tens == 0;
- bool check4 = units != 0 && n % units == 0;
- if (check1 && check2 && check3 && check4) {
- cout << number << " ";
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment