Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- namespace _04._Triple_Sum
- {
- class TripleSum
- {
- static void Main(string[] args)
- {
- int[] numbers = Console.ReadLine().Split().Select(int.Parse).ToArray();
- bool foundSum = TripleeSum(numbers);
- if (!foundSum)
- {
- Console.WriteLine("No");
- }
- }
- private static bool TripleeSum(int[] numbers)
- {
- bool found = false;
- for (int i = 0; i < numbers.Length - 1; i++)
- {
- for (int j = i + 1; j < numbers.Length; j++)
- {
- int sum = numbers[i] + numbers[j];
- if (numbers.Contains(sum))
- {
- found = true;
- Console.WriteLine($"{numbers[i]} + {numbers[j]} == {sum}");
- }
- }
- }
- return found;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment