瀏覽代碼

apparently, i1 and i2 can be equal

tarfeef101 7 年之前
父節點
當前提交
879864d9cd
共有 2 個文件被更改,包括 2 次插入2 次删除
  1. 二進制
      q5/q5_test
  2. 2 2
      q5/q5a.cpp

二進制
q5/q5_test


+ 2 - 2
q5/q5a.cpp

@@ -27,14 +27,14 @@ int main()
 	nums >> b[i];
     }
     
-    int clen = (n * (n - 1)) / 2; // total possible sums in an array of length n
+    int clen = (n * (n + 1)) / 2; // total possible sums in an array of length n
     int * c = (int *) malloc(clen * sizeof(int));
     int tempcount = 0;
     
     // Store within c the possible sums inside b
     for (int i = 0; i < n; ++i)
     {
-        for (int j = (i + 1); j < n; ++j, ++tempcount)
+        for (int j = i; j < n; ++j, ++tempcount)
         {
             c[tempcount] = b[i] + b[j];
         }