kvadrat4o

Untitled

Jul 13th, 2017
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.40 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 n = int.Parse(Console.ReadLine());
  14.             int m = int.Parse(Console.ReadLine());
  15.             int y = int.Parse(Console.ReadLine());
  16.             int counter = 0;
  17.             int j1 = 0;
  18.             int i1 = 0;
  19.             int countr = 0;
  20.             for (int i = n; i >= m; i--)
  21.             {
  22.                 for (int j = n; j >= m; j--)
  23.                 {
  24.                     if (i1 + j1 == y)
  25.                     {
  26.                         break;
  27.                     }
  28.                     countr++;
  29.                     if (i + j ==y)
  30.                     {                        
  31.                         i1 = i;
  32.                         j1 = j;
  33.                         break;
  34.                     }
  35.                     else
  36.                     {
  37.                         counter++;
  38.                     }
  39.                 }
  40.             }
  41.             if (i1 + j1 == y)
  42.             {
  43.                 Console.WriteLine("Combination N:{0} ({1} + {2} = {3})", countr,i1, j1, y);
  44.             }
  45.             else
  46.             {
  47.                 Console.WriteLine("{0} combinations - neither equals {1}", counter, y);
  48.             }
  49.            
  50.         }
  51.     }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment