Advertisement
Sim0o0na

06. Sum And Product

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