bacco

Сбор или Произведение

Feb 22nd, 2018
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.86 KB | None | 0 0
  1. using System;
  2.  
  3. namespace Купа
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             int startNumber = int.Parse(Console.ReadLine());
  10.  
  11.             bool valid = false;
  12.  
  13.             for (int a = 1; a <= 30; a++)
  14.             {
  15.                 for (int b = 1; b <= 30; b++)
  16.                 {
  17.                     for (int c = 1; c <= 30; c++)
  18.                     {
  19.                         if (a + b + c == startNumber)
  20.                         {
  21.                             if (a < b && b < c && a < c)
  22.                             {
  23.                                 Console.WriteLine($"{a} + {b} + {c} = {startNumber}");
  24.                                 valid = true;
  25.                             }
  26.                         }
  27.  
  28.                         if (a * b * c == startNumber)
  29.                         {
  30.                             if (a > b && b > c && a > c)
  31.                             {
  32.                                 Console.WriteLine($"{a} * {b} * {c} = {startNumber}");
  33.                                 valid = true;
  34.                             }  
  35.                         }
  36.                     }
  37.                 }
  38.  
  39.             }
  40.             if (!valid)
  41.             {
  42.                Console.WriteLine("No!");
  43.             }
  44.  
  45.         }
  46.     }
  47.  
  48. }
  49.  
  50. //                            Сбор или Произведение
  51.  
  52. //                                    12
  53.  
  54. //                               1 + 2 + 9 = 12
  55. //                               1 + 3 + 8 = 12
  56. //                               1 + 4 + 7 = 12
  57. //                               1 + 5 + 6 = 12
  58. //                               2 + 3 + 7 = 12
  59. //                               2 + 4 + 6 = 12
  60. //                               3 + 4 + 5 = 12
  61. //                               4 * 3 * 1 = 12
  62. //                               6 * 2 * 1 = 12
Advertisement
Add Comment
Please, Sign In to add comment