Advertisement
AlexTasev

SumAndProduct

Apr 28th, 2018
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.16 KB | None | 0 0
  1. using System;
  2.  
  3. namespace _6_SumAndProduct
  4. {
  5.     class Program
  6.     {
  7.         static void Main()
  8.         {
  9.             int n = int.Parse(Console.ReadLine());
  10.  
  11.             for (int a = 1; a <= 9; a++)
  12.             {
  13.                 for (int b = 9; b >=  a; b--)
  14.                 {
  15.                     for (int c = 0; c <= 9; c++)
  16.                     {
  17.                         for (int d = 9; d >= c; d--)
  18.                         {
  19.                             int sum = a + b + c + d;
  20.                             int mult = a * b * c * d;
  21.  
  22.                             if (sum == mult && n % 10 == 5)
  23.                             {
  24.                                 Console.WriteLine($"{a}{b}{c}{d}");
  25.                                 return;
  26.                             }
  27.                             else if (mult / sum == 3 && n % 3 == 0)
  28.                             {
  29.                                 Console.WriteLine($"{d}{c}{b}{a}");
  30.                                 return;
  31.                             }
  32.                         }
  33.                     }
  34.                 }
  35.  
  36.             }
  37.             Console.WriteLine("Nothing found");
  38.         }
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement