Determine if any two integers in array sum to given integer
static void Main(string[]
args) { int[] arr = new int[] {
1, 4, 2, 9, 5, 6, 3, 11 };
Console.Write("Enter the Traget Number : ");
int
number = int.Parse(Console.ReadLine());
if (
TwoIntegersSumToTarget(arr, number))
Console.WriteLine("Given sum number exist"); else
Console.WriteLine("Given sum number not exist");
Console.ReadLine();
} public static bool
TwoIntegersSumToTarget(int[] arr, int target) { for (int i =
0; i < arr.Length; i++) { for (int k =
0; k < arr.Length; k++) {
if (i != k)
{ int sum =
arr[i] + arr[k];
if (sum == target) return true;
} } } return false; } |
EmoticonEmoticon