Run Code  | API  | Code Wall  | Misc  | Feedback  | Login  | Theme  | Privacy  | Patreon 

return whether any two numbers from the list add up to k


            
                
            
 run  | edit  | history  | help 0
Code

using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions;

namespace Rextester {

public class Program {

public static void Main(string[] args) { int[] array1 = new int[] { 1, -3, 5, 7, 10,-9,-2,11,19,12,17,23,132,189,100}; int k = 1231;

List < int > l = new List < int > (); foreach(var item in array1) {

if (array1.Contains(k - item)&&((k - item)!=item)) {

if (!l.Contains(item)) { Console.WriteLine(item.ToString() + "+" + (k - item).ToString()+"="+k); l.Add((k - item)); } }
} if(l.Count()<1) { Console.WriteLine("No additives found"); } } } }

  by  Rehan Ahmed, 4 months ago




Please log in to post a comment.
dfg
7