desislava_topuzakova

06. Special Numbers начин 2

May 31st, 2020
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.37 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.             //1111 до 9999
  12.             for (int thousands = 1; thousands <= 9; thousands++)
  13.             {
  14.                 for (int hundreds = 1; hundreds <= 9; hundreds++)
  15.                 {
  16.                     for (int tens = 1; tens <= 9; tens++)
  17.                     {
  18.                         for (int units = 1; units <= 9; units++)
  19.                         {
  20.                             //генерираме всички числа от 1111 до 9999
  21.                             bool check1 = thousands != 0 && n % thousands == 0;
  22.                             bool check2 = hundreds != 0 && n % hundreds == 0;
  23.                             bool check3 = tens != 0 && n % tens == 0;
  24.                             bool check4 = units != 0 && n % units == 0;
  25.  
  26.                             //специално ако са изпълнени 4-те неща
  27.                             if (check1 && check2 && check3 && check4)
  28.                             {
  29.                                 Console.Write($"{thousands}{hundreds}{tens}{units} ");
  30.                             }
  31.                         }
  32.                     }
  33.                 }
  34.             }
  35.         }
  36.     }
  37. }
Add Comment
Please, Sign In to add comment