desislava_topuzakova

06. Special Numbers начин 1

May 31st, 2020
238
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.22 KB | None | 0 0
  1. using System;
  2. using System.IO.IsolatedStorage;
  3.  
  4. namespace NestedLoops
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             int n = int.Parse(Console.ReadLine());
  11.  
  12.             //1111 до 9999
  13.             for (int number = 1111; number <= 9999; number++)
  14.             {
  15.                 //проверка дали е специално:
  16.                 //вземе всяка една от цифрите ->
  17.                 int thousands = number / 1000;
  18.                 int hundreds = (number / 100) % 10;
  19.                 int tens = (number / 10) % 10;
  20.                 int units = number % 10;
  21.                 //проверка да е специално -> n %  == 0
  22.                 bool check1 = thousands != 0 && n % thousands == 0;
  23.                 bool check2 = hundreds != 0 && n % hundreds == 0;
  24.                 bool check3 = tens != 0 && n % tens == 0;
  25.                 bool check4 = units != 0 && n % units == 0;
  26.  
  27.                 //специално ако са изпълнени 4-те неща
  28.                 if(check1 && check2 && check3 && check4)
  29.                 {
  30.                     Console.Write(number + " ");
  31.                 }
  32.  
  33.  
  34.             }
  35.         }
  36.     }
  37. }
Add Comment
Please, Sign In to add comment