Pārlūkot izejas kodu

apparently, i1 and i2 can be equal

tarfeef101 7 gadi atpakaļ
vecāks
revīzija
879864d9cd
2 mainītis faili ar 2 papildinājumiem un 2 dzēšanām
  1. BIN
      q5/q5_test
  2. 2 2
      q5/q5a.cpp

BIN
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];
         }