2015-09-27 18 views
-1

我有這個號碼:
我怎樣才能檢測到我在c#中輸出總和的數字總和?

Int64[] arr1 = new Int64[] { 28811251, 19374713, 9602311, 217578282, 461715268, 3983660, 231978436, 9791904, 11206597, 62907620, 156311365, 7527222, 8340887 }; 


和我想寫的C#Windows應用程序查找兩個數字之和等於出sum=984724000

+0

[查看此解決方案](http://codereview.stackexchange.com/questions/21405/maximum-sub-array-problem)。 –

回答

0
for (int i = 0; i < arr1.Length; i++) 
for (int j = 0; j < arr1.Length; j++) 
{ 
    if (i == j) continue; 

    Int64 sum = arr1[i] + arr1[j]; 
    if (sum == 984724000) 
     Console.WriteLine(arr1[i].ToString() + "+" + arr1[j].ToString()) 
} 
+0

我可以問爲什麼'if(i == j)繼續;' –

+0

,因爲您正在爲自己添加相同的值 –

+0

Stackoverflow:「此編輯旨在解決作者的帖子,並沒有任何意義上的編輯。應該寫成評論或答案。「其實,我想要做的只是添加一個+和一個;使其成爲有效的可編譯c#,但堆棧溢出不允許少於6個字符的編輯:) –

相關問題