Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 8. Magic Sum
- Write a program, which prints all unique pairs in an array of integers whose sum is equal to a given number.
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace _08MagicSum
- {
- class Program
- {
- static void Main(string[] args)
- {
- int[] array = Console.ReadLine().Split().Select(int.Parse).ToArray();
- var number = int.Parse(Console.ReadLine());
- int magicSum = 0;
- for (int i = 0; i < array.Length - 1; i++)
- {
- for (int a = i + 1; a < array.Length; a++)
- {
- magicSum = array[i] + array[a];
- if (magicSum == number)
- {
- Console.WriteLine(string.Join(" ", array[i], array[a]));
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment