Advertisement
dimipan80

Exam 1. Print_Nine_Digit_Magic_Numbers

Jun 1st, 2014
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.65 KB | None | 0 0
  1. namespace _4.Nine_DigitMagicNumbers
  2. {
  3.     using System;
  4.  
  5.     public class MagicNumbers
  6.     {
  7.         public static void Main(string[] args)
  8.         {
  9.             checked
  10.             {
  11.                 int sum = int.Parse(Console.ReadLine());
  12.                 int diff = int.Parse(Console.ReadLine());
  13.  
  14.                 bool foundMagicNumber = false;
  15.                 int a, b, c, d, e, f, g, h, i;
  16.                 for (a = 1; a <= 7; a++)
  17.                 {
  18.                     for (b = 1; b <= 7; b++)
  19.                     {
  20.                         for (c = 1; c <= 7; c++)
  21.                         {
  22.                             int firstNum = (a * 100) + (b * 10) + c;
  23.                             for (d = 1; d <= 7; d++)
  24.                             {
  25.                                 for (e = 1; e <= 7; e++)
  26.                                 {
  27.                                     for (f = 1; f <= 7; f++)
  28.                                     {
  29.                                         int secondNum = (d * 100) + (e * 10) + f;
  30.                                         if (secondNum - firstNum == diff)
  31.                                         {
  32.                                             for (g = 1; g <= 7; g++)
  33.                                             {
  34.                                                 for (h = 1; h <= 7; h++)
  35.                                                 {
  36.                                                     for (i = 1; i <= 7; i++)
  37.                                                     {
  38.                                                         int thirdNum = (g * 100) + (h * 10) + i;
  39.                                                         int currentSum = a + b + c + d + e + f + g + h + i;
  40.                                                         if (currentSum == sum && thirdNum - secondNum == diff)
  41.                                                         {
  42.                                                             foundMagicNumber = true;
  43.                                                             Console.WriteLine("{0}{1}{2}", firstNum, secondNum, thirdNum);
  44.                                                         }
  45.                                                     }
  46.                                                 }
  47.                                             }
  48.                                         }
  49.                                     }
  50.                                 }
  51.                             }
  52.                         }
  53.                     }
  54.                 }
  55.  
  56.                 if (!foundMagicNumber)
  57.                 {
  58.                     Console.WriteLine("No");
  59.                 }
  60.             }
  61.         }
  62.     }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement