Advertisement
filipovv

#13

May 27th, 2017
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.17 KB | None | 0 0
  1.  
  2.  
  3. 1
  4. using System;
  5. 2
  6.  
  7. 3
  8. namespace GameOfNums
  9. 4
  10. {
  11. 5
  12.     class MainClass
  13. 6
  14.     {
  15. 7
  16.         public static void Main(string[] args)
  17. 8
  18.         {
  19. 9
  20.             int n = int.Parse(Console.ReadLine());
  21. 10
  22.             int m = int.Parse(Console.ReadLine());
  23. 11
  24.             int magic = int.Parse(Console.ReadLine());
  25. 12
  26.  
  27. 13
  28.             int counter = 0;
  29. 14
  30.             int combination = 0;
  31. 15
  32.  
  33. 16
  34.             for (int i = n; i <= m; i++)
  35. 17
  36.             {
  37. 18
  38.                 for (int j = n; j <= m; j++)
  39. 19
  40.                 {
  41. 20
  42.                     if (j+i==magic)
  43. 21
  44.                     {
  45. 22
  46.                         Console.WriteLine($"Number found! {j} + {i} = {magic}");
  47. 23
  48.                         combination++;break;
  49. 24
  50.                     }
  51. 25
  52.                     counter++;
  53. 26
  54.                 }
  55. 27
  56.                 if (combination>0)
  57. 28
  58.                 {
  59. 29
  60.                     break;
  61. 30
  62.                 }
  63. 31
  64.             }
  65. 32
  66.             if (combination==0)
  67. 33
  68.             {
  69. 34
  70.                 Console.WriteLine($"{counter} combinations - neither equals {magic}");
  71. 35
  72.             }
  73. 36
  74.  
  75. 37
  76.  
  77. 38
  78.         }
  79. 39
  80.     }
  81. 40
  82. }
  83. 41
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement