Advertisement
viraco4a

13. Game of Numbers

May 22nd, 2018
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace _13_GameOfNumbers
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. int N = int.Parse(Console.ReadLine());
  14. int M = int.Parse(Console.ReadLine());
  15. int Magic = int.Parse(Console.ReadLine());
  16. int comb = 0;
  17. int sum = 0;
  18. int last = 0;
  19. int first = 0;
  20. int second = 0;
  21. for (int i = N; i <= M; i++)
  22. {
  23. for (int j = N; j <= M; j++)
  24. {
  25. sum = i + j;
  26. comb++;
  27. if (sum == Magic)
  28. {
  29. last = sum;
  30. first = i;
  31. second = j;
  32. }
  33. }
  34. }
  35. if (last == 0)
  36. {
  37. Console.WriteLine($"{comb} combinations - neither equals {Magic}");
  38. }
  39. else
  40. {
  41. Console.WriteLine($"Number found! {first} + {second} = {Magic}");
  42. }
  43. }
  44. }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement