Advertisement
YavorGrancharov

Game_of_Numbers

Jun 3rd, 2017
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.24 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 Game_of_Numbers
  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 mag = int.Parse(Console.ReadLine());
  16.  
  17.             int i, j;
  18.  
  19.             int sum = 0;
  20.  
  21.             int count = 0;
  22.  
  23.             int match = 0;
  24.  
  25.             if (n >= 1 && n <= 999 && m >= 1 && m <= 1000)
  26.             {
  27.                 for (i = m; i >= n; i--)
  28.                 {
  29.                     for (j = m; j >= n; j--)
  30.                     {
  31.                         sum = i + j;
  32.                         count++;
  33.  
  34.                         if (sum == mag)
  35.                         {
  36.                             Console.WriteLine($"Number found! {i} + {j} = {mag}");
  37.                             match++;
  38.                             return;
  39.                         }
  40.                     }
  41.                 }
  42.                 if (match == 0)
  43.                 {
  44.                     Console.WriteLine($"{count} combinations - neither equals {mag}");
  45.                 }
  46.             }
  47.         }
  48.     }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement