MiroslavKisov

Sum_Of_Two_Numbers

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