MiroslavKisov

Two_Numbers_Sum

Aug 9th, 2017
620
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.26 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 Two_Numbers_Sum
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             int end = int.Parse(Console.ReadLine());
  14.             int start = int.Parse(Console.ReadLine());
  15.             int magicNumber = int.Parse(Console.ReadLine());
  16.             int combinationCounter = 0;
  17.             bool isNumberMagic = false;
  18.             for (int i = end; i >= start; i--)
  19.             {
  20.                 if(isNumberMagic==true)
  21.                 {
  22.                     break;
  23.                 }
  24.                 for (int j = end; j >= start; j--)
  25.                 {
  26.                     combinationCounter++;
  27.                     if (i + j == magicNumber)
  28.                     {
  29.                         Console.WriteLine("Combination N:{0} ({1} + {2} = {3})", combinationCounter, i, j, magicNumber);
  30.                         isNumberMagic = true;
  31.                         break;
  32.                     }
  33.                 }
  34.             }
  35.             if (isNumberMagic==false)
  36.             {
  37.                 Console.WriteLine("{0} combinations - neither equals {1}", combinationCounter, magicNumber);
  38.             }
  39.         }
  40.     }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment