tanya_zheleva

Tripple Sum

Jan 30th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.94 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace ExamPreparation
  6. {
  7.     class Startup
  8.     {
  9.         static void Main()
  10.         {
  11.             int[] numbers = Console.ReadLine()
  12.                 .Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
  13.                 .Select(int.Parse)
  14.                 .ToArray();
  15.             int found = 0;
  16.  
  17.             for (int j = 0; j < numbers.Length; j++)
  18.             {
  19.                 for (int k = j + 1; k < numbers.Length; k++)
  20.                 {
  21.                     int sum = numbers[j] + numbers[k];
  22.  
  23.                     if (numbers.Contains(sum))
  24.                     {
  25.                         Console.WriteLine($"{numbers[j]} + {numbers[k]} == {sum}");
  26.                         found++;
  27.                     }
  28.                 }
  29.             }
  30.  
  31.             if (found == 0)
  32.             {
  33.                 Console.WriteLine("No");
  34.             }
  35.         }
  36.     }
  37. }
Add Comment
Please, Sign In to add comment