Advertisement
Valantina

MathPuzzle/Exam

Jun 15th, 2019
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.09 KB | None | 0 0
  1. using System;
  2.  
  3. namespace MathPuzzle
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             int key = int.Parse(Console.ReadLine());
  10.             bool validCombinations = false;
  11.  
  12.             for (int a = 1; a <= 30; a++)
  13.             {
  14.                 for (int b = 1; b <= 30; b++)
  15.                 {
  16.                     for (int c = 1; c <= 30; c++)
  17.                     {
  18.                         if(a + b +c == key && a < b & b < c)
  19.                         {
  20.                             Console.WriteLine($"{a} + {b} + {c} = {key}");
  21.                             validCombinations = true;
  22.                         }
  23.                         if (a * b * c == key && a > b && b > c)
  24.                         {
  25.                             Console.WriteLine($"{a} * {b} * {c} = {key}");
  26.                             validCombinations = true;
  27.                         }
  28.                     }
  29.                 }
  30.             }
  31.             if (validCombinations == false)
  32.             {
  33.                 Console.WriteLine("No!");
  34.             }
  35.         }
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement