bacco

Two Numbers Sum

Mar 1st, 2018
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.87 KB | None | 0 0
  1. using System;
  2.  
  3. namespace КоледнаШапка
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             var startNum = int.Parse(Console.ReadLine());
  10.             var endNum = int.Parse(Console.ReadLine());
  11.             var magicNum = int.Parse(Console.ReadLine());
  12.  
  13.             var count = 0;
  14.  
  15.             for (int a = startNum; a >= endNum; a--)
  16.             {
  17.                 for (int b = startNum; b >= endNum; b--)
  18.                 {
  19.                     count++;
  20.  
  21.                     if (a + b == magicNum)
  22.                     {
  23.                         Console.WriteLine($"Combination N:{count} ({a} + {b} = {a + b})");
  24.                         Environment.Exit(0);
  25.                     }
  26.                 }
  27.             }
  28.  
  29.             Console.WriteLine($"{count} combinations - neither equals {magicNum}");
  30.         }
  31.     }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment