I am a new C# programmer and am currently stuck on the following problem:
Given an array of numbers =
[49, 71, 68, 26, 58, 64, 47, 16, 42, 53, 20, 15, 17, 45, 43, 52, 88, 65, 46, 82, 86,
69, 84, 56, 54, 28, 60, 32, 95, 29, 9, 79, 98, 51, 90, 36, 24, 62, 14, 91, 83, 3,
74, 30, 33, 6, 92, 40, 70, 2, 44, 31, 55, 12, 8, 89, 37, 72, 25, 81, 23, 100, 13,
87, 80, 18, 85, 5, 78, 10, 75, 41, 67, 94, 27, 96, 22, 73, 21, 63, 7, 34, 39, 61,
4, 19, 97, 93, 11, 35, 77, 76, 48, 57, 50, 99, 1, 59, 66, 38]
Write a C# function that will return a comma separated string of the first two numbers in the array which sum to 30 and immediately exit.
I've been working on this for a while, and it seems simple enough, however this is all I have been able to come up with:
using System;
using System.Collections.Generic;
using System.Linq;
class Program
{
static void Main()
{
int[] array1 = { 49, 71, 68, 26, 58, 64, 47, 16, 42, 53, 20, 15, 17, 45, 43, 52, 88, 65, 46, 82, 86, 69, 84, 56, 54, 28, 60, 32, 95, 29, 9, 79, 98, 51, 90, 36, 24, 62, 14, 91, 83, 3, 74, 30, 33, 6, 92, 40, 70, 2, 44, 31, 55, 12, 8, 89, 37, 72, 25, 81, 23, 100, 13, 87, 80, 18, 85, 5, 78, 10, 75, 41, 67, 94, 27, 96, 22, 73, 21, 63, 7, 34, 39, 61, 4, 19, 97, 93, 11, 35, 77, 76, 48, 57, 50, 99, 1, 59, 66, 38 };
int sum1 = array1.Sum();
Console.WriteLine(sum1);
}
}
I know that I'm just missing something small and I have found similar problems but none have solved this one for me. Any help or push in the right direction would be appreciated.