Advertisement
Guest User

Untitled

a guest
May 27th, 2017
352
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.44 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 Practice_
  8. {
  9.     public class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             int n = int.Parse(Console.ReadLine());
  14.             int m = int.Parse(Console.ReadLine());
  15.             int magicalNumbers = int.Parse(Console.ReadLine());
  16.             int combinations = 0, firstNumber = 0, secondNumer = 0;
  17.             var lastCombination = string.Empty;/// store LAST combination that is equal of the sum.
  18.             for (firstNumber = n; firstNumber <= m; firstNumber++)
  19.             {
  20.                 for (secondNumer = n; secondNumer <= m; secondNumer++)
  21.                 {
  22.                     combinations++;
  23.  
  24.                     if (firstNumber + secondNumer == magicalNumbers && firstNumber > secondNumer)
  25.                     {
  26.                         lastCombination = $"Number found! {firstNumber} + {secondNumer} = {magicalNumbers}";
  27.  
  28.                     }  
  29.                     /// I removed the second if statemant
  30.                 }
  31.             }
  32.  
  33.             if (lastCombination==string.Empty) /// checking if it is empty.
  34.                 Console.WriteLine($"{combinations} combinations - neither equals {magicalNumbers}");
  35.             else /// if it is not empty then it has found the last combination.
  36.                 Console.WriteLine(lastCombination);
  37.         }
  38.     }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement