Advertisement
kirililchev3

Game of Numbers - for loops

May 20th, 2018
307
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.03 KB | None | 0 0
  1. using System;
  2.  
  3. namespace P13GameOfNumbers
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             int n = int.Parse(Console.ReadLine());
  10.             int m = int.Parse(Console.ReadLine());
  11.             int magicNum = int.Parse(Console.ReadLine());
  12.  
  13.             int combinations = 0;
  14.             var lastComb = string.Empty;
  15.            
  16.                
  17.             for (int k = n; k <= m; k++)
  18.             {
  19.                 for (int j = n; j <= m; j++)
  20.                 {
  21.                     combinations++;
  22.                     if (k + j== magicNum && k > j)
  23.                     {
  24.                         lastComb = $"Number found! {k} + {j} = {magicNum}";
  25.                     }
  26.                 }
  27.             }
  28.             if (lastComb == string.Empty)
  29.             {
  30.                 Console.WriteLine($"{combinations} combinations - neither equals {magicNum}");
  31.             }
  32.             else
  33.             {
  34.                 Console.WriteLine(lastComb);
  35.             }
  36.         }
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement