veronikaaa86

13. Game of Numbers

Jan 31st, 2018
276
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.22 KB | None | 0 0
  1. namespace Ex13_GameOfNumbers
  2. {
  3.     using System;
  4.     public class Program
  5.     {
  6.         public static void Main(string[] args)
  7.         {
  8.             int N = int.Parse(Console.ReadLine());
  9.             int M = int.Parse(Console.ReadLine());
  10.             int magic = int.Parse(Console.ReadLine());
  11.  
  12.             int first = 0;
  13.             int second = 0;
  14.             int sum = 0;
  15.             int counter = 0;
  16.  
  17.             for (int i = M; i >= N; i--)
  18.             {
  19.                 for (int j = M; j >= N; j--)
  20.                 {
  21.                     counter++;
  22.                     first = i;
  23.                     second = j;
  24.                     sum = i + j;
  25.  
  26.                     if (sum == magic)
  27.                     {
  28.                         break;
  29.                     }
  30.                 }
  31.                 if (sum == magic)
  32.                 {
  33.                    
  34.                     break;
  35.                 }
  36.             }
  37.  
  38.             if (sum == magic)
  39.             {
  40.                 Console.WriteLine($"Number found! {first} + {second} = {magic}");
  41.             }
  42.             else
  43.             {
  44.                 Console.WriteLine($"{counter} combinations - neither equals {magic}");
  45.             }
  46.         }
  47.     }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment