Advertisement
radidim

08.Magic Sum (C# Shell App Paste)

Jan 1st, 2019
335
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.10 KB | None | 0 0
  1. //Disclaimer: The creator of 'C# Shell (C# Offline Compiler)' is in no way responsible for the code posted by any user.
  2. Disclaimer: The creator of 'C# Shell (C# Offline Compiler)' is in no way responsible for the code posted by any user.
  3. using System;
  4. using System.IO;
  5. using System.Linq;
  6. using System.Collections.Generic;
  7.  
  8. namespace CSharp_Shell
  9. {
  10.  
  11.     public static class Program
  12.     {
  13.         public static void Main()
  14.         {
  15.            //Write a program, which prints all unique pairs in an array of integers whose sum is equal to a given number.
  16.            int[] arr = Console.ReadLine()
  17.            .Split()
  18.            .Select(int.Parse)
  19.            .ToArray();
  20.            
  21.            //result=0;
  22.            int num = int.Parse(Console.ReadLine());
  23.            for(int i =0; i< arr.Length-1;i++)
  24.            {
  25.                for(int j=i+1; j<arr.Length;j++)
  26.                {
  27.                    
  28.                
  29.                if(arr[i] + arr[j]==num)
  30.                {
  31.                    Console.WriteLine($"{arr[i]} {arr[j]}");
  32.                }
  33.                    
  34.                }
  35.            }
  36.            
  37.  
  38.         }
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement