Advertisement
Guest User

Two Numbers Sum

a guest
Nov 24th, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.97 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 TwoNumbersS
  8. {
  9.     class TwoNumbersS
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             int startN = int.Parse(Console.ReadLine());
  14.             int endN = int.Parse(Console.ReadLine());
  15.             int magicN = int.Parse(Console.ReadLine());
  16.             int combinations = 0;
  17.  
  18.             for (int i = startN; i >= endN; i--)
  19.             {
  20.                 for (int j = startN; j >= endN; j--)
  21.                 {
  22.                     combinations++;
  23.                     if (i + j == magicN)
  24.                     {
  25.                         Console.WriteLine($"Combination N:{combinations} ({i} + {j} = {magicN})");
  26.                         return;
  27.                     }                
  28.                 }
  29.             }
  30.             Console.WriteLine($"{combinations} combinations - neither equals {magicN}");
  31.         }
  32.     }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement