aspire12

08.MagicSum

Feb 16th, 2020
228
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.79 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. namespace _08.MagicSum
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             //Write a program, which prints all unique pairs in an array of integers whose sum is equal to a given number.
  10.  
  11.             int[] inputArray = Console.ReadLine().Split().Select(int.Parse).ToArray();
  12.             int sum = int.Parse(Console.ReadLine());
  13.  
  14.             for (int i = 0; i < inputArray.Length; i++)
  15.             {
  16.                 for (int j = i + 1; j < inputArray.Length; j++)
  17.                 {
  18.                     if(inputArray[i] + inputArray[j] == sum)
  19.                     {
  20.                         Console.WriteLine(inputArray[i] + " " + inputArray[j]);
  21.                     }
  22.                 }
  23.             }
  24.         }
  25.     }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment