YavorGrancharov

Problem_06___Two_Numbers_Sum

Jul 15th, 2017
108
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 Problem_06___Two_Numbers_Sum
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             int start = int.Parse(Console.ReadLine());
  10.             int end = int.Parse(Console.ReadLine());
  11.             int magic = int.Parse(Console.ReadLine());
  12.  
  13.             int count = 0;
  14.             int i = 0;
  15.             int j = 0;
  16.             bool found = i + j == magic;
  17.  
  18.             for ( i = start; i >= end; i--)
  19.             {
  20.                 for ( j = start; j >= end; j--)
  21.                 {
  22.                     count++;
  23.                     if (i + j == magic)
  24.                     {
  25.                         Console.WriteLine("Combination N:{0} ({1} + {2} = {3})", count, i, j, magic);
  26.                         return;                    
  27.                     }                  
  28.                 }
  29.             }
  30.             if (!found)
  31.             {
  32.                 Console.WriteLine("{0} combinations - neither equals {1}", count, magic);
  33.             }          
  34.         }
  35.     }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment