Advertisement
skipter

C# - Game of Numbers / Hardcore

Jun 3rd, 2017
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.92 KB | None | 0 0
  1. using System;
  2. class Program
  3. {
  4.     static void Main()
  5.     {
  6.         int firstNum = int.Parse(Console.ReadLine());
  7.         int secondNum = int.Parse(Console.ReadLine());
  8.         int magicNum = int.Parse(Console.ReadLine());
  9.  
  10.         int counter = 0;
  11.         int sum = 0;
  12.         int secondCounter = 0;
  13.  
  14.         for (int i = secondNum; i >= firstNum; i--)
  15.         {
  16.             for (int j = secondNum; j >= firstNum; j--)
  17.             {
  18.                 counter++;
  19.                 sum = i + j;
  20.                 if (sum == magicNum)
  21.                 {
  22.                    
  23.                     Console.WriteLine("Number found! {0} + {1} = {2}", i, j, magicNum);
  24.                     secondCounter++;
  25.                     return;
  26.                 }
  27.             }
  28.         }
  29.         if (secondCounter == 0)
  30.         {
  31.             Console.WriteLine("{0} combinations - neither equals {1}", counter, magicNum);
  32.         }
  33.     }  
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement