bacco

Сума от две числа

Feb 28th, 2018
252
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.92 KB | None | 0 0
  1. using System;
  2.  
  3. namespace dwdwdwdwDD
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             var startNum = int.Parse(Console.ReadLine());
  10.             var endNum = int.Parse(Console.ReadLine());
  11.             var magicNum = int.Parse(Console.ReadLine());
  12.  
  13.             var count = 0;
  14.             var c = 0;
  15.  
  16.             for (int a = startNum; a <= endNum; a++)
  17.             {
  18.                 for (int b = startNum; b <= endNum; b++)
  19.                 {
  20.                     c = a + b;
  21.                     count++;
  22.                     if (c == magicNum)
  23.                     {
  24.                         Console.Write($"Combination N:{count} ({a} + {b} = {c})");
  25.                         Environment.Exit(0);
  26.                     }
  27.  
  28.                 }
  29.                
  30.             }
  31.             Console.WriteLine($"{count} combinations - neither equals {magicNum}");
  32.  
  33.         }
  34.     }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment