Advertisement
Zaksofon

Untitled

Mar 1st, 2020
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.31 KB | None | 0 0
  1. using System;
  2.  
  3. namespace _06._Exam___Math_Puzzle
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             int keyNumber = int.Parse(Console.ReadLine());
  10.             int combinationNumber = 0;
  11.             for (int a = 1; a <= 30; a++)
  12.             {
  13.                 for (int b = 1; b <= 30; b++)
  14.                 {
  15.                     for (int c = 0; c <= 30; c++)
  16.                     {
  17.                         if (a + b + c == keyNumber)
  18.                         {
  19.                             if (a < b && b < c)
  20.                             {
  21.                                 Console.WriteLine($"{a} + {b} + {c} = {a + b + c}");
  22.                                 combinationNumber++;
  23.                             }
  24.                         }
  25.                         else if (a * b * c == keyNumber)
  26.                         {
  27.                             if (c < b && b < a)
  28.                             {
  29.                                 Console.WriteLine($"{a} * {b} * {c} = {a * b * c}");
  30.                                 combinationNumber++;
  31.                             }
  32.                         }
  33.                     }
  34.                 }
  35.             }
  36.             if (combinationNumber == 0)
  37.             {
  38.                 Console.WriteLine("No!");
  39.             }
  40.         }
  41.     }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement