Advertisement
TeMePyT

Untitled

Jun 1st, 2018
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.09 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. namespace _04._Triple_Sum
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.            int sum = 0;
  11.            int counter = 0;
  12.            int[] arr = Console.ReadLine().Split().Select(int.Parse).ToArray();
  13.            for (int i = 0; i < arr.Length - 1; i++)
  14.             {
  15.                 for (int j = 1; j <= arr.Length; j++)
  16.                 {
  17.                     if (i + j < arr.Length)
  18.                     {
  19.                         sum = arr[i] + arr[i + j];
  20.                     }
  21.                     for (int k = 0; k < arr.Length; k++)
  22.                     {
  23.                         if (sum == arr[k] && (i + j < arr.Length))
  24.                         {
  25.                             Console.WriteLine($"{arr[i]} + {arr[i + j]} == {arr[k]}");
  26.                             counter += 1;
  27.                             break;
  28.                         }
  29.                     }
  30.                 }
  31.             }
  32.             if (counter == 0)
  33.             {
  34.                 Console.WriteLine("No");
  35.             }
  36.  
  37.         }
  38.     }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement