Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In C, The following loop is supposed to print all the positive values in array A

ID: 642297 • Letter: I

Question

In C,

The following loop is supposed to print all the positive values in array A. Fill in the missing single statement below so that it prints the correct values. The correct statement consists of a single word followed by a semi-colon.

            for (i = 0; i< N; ++i) {
        if (A[i] <= 0)
          ________________________;
     print A[i];
}

The following loop is supposed to print the values of A up to, but not including, the first entry that is not equal to the corresponding entry in B. The correct statement consists of a single word followed by a semi-colon.

            for (i = 0; i< N; ++i) {
           if (A[i] != B[i])
                ________________________;
           print A[i];
     }

Explanation / Answer

for (i = 0; i< N; ++i) {
        if (A[i] <= 0)
          continue;
     print A[i];
}

for (i = 0; i< N; ++i) {
           if (A[i] != B[i])
                break;
           print A[i];
     }