Advertisement
filipovv

#13(1)

May 27th, 2017
252
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.13 KB | None | 0 0
  1.  
  2.  
  3. 1 using System;
  4. 2  
  5. 3 namespace GameOfNums
  6. 4 {
  7. 5     class MainClass
  8. 6     {
  9. 7         public static void Main(string[] args)
  10. 8         {
  11. 9             int n = int.Parse(Console.ReadLine());
  12. 10             int m = int.Parse(Console.ReadLine());
  13. 11             int magic = int.Parse(Console.ReadLine());
  14. 12  
  15. 13             int counter = 0;
  16. 14             int combination = 0;
  17. 15  
  18. 16             for (int i = n; i <= m; i++)
  19. 17             {
  20. 18                 for (int j = n; j <= m; j++)
  21. 19                 {
  22. 20                     if (j+i==magic)
  23. 21                     {
  24. 22                         Console.WriteLine($"Number found! {j} + {i} = {magic}");
  25. 23                         combination++;break;
  26. 24                     }
  27. 25                     counter++;
  28. 26                 }
  29. 27                 if (combination>0)
  30. 28                 {
  31. 29                     break;
  32. 30                 }
  33. 31             }
  34. 32             if (combination==0)
  35. 33             {
  36. 34                 Console.WriteLine($"{counter} combinations - neither equals {magic}");
  37. 35             }
  38. 36  
  39. 37  
  40. 38         }
  41. 39     }
  42. 40 }
  43. 41
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement