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

Execute the following coding segment and identify the errors in the program. Deb

ID: 3844611 • Letter: E

Question

Execute the following coding segment and identify the errors in the program. Debug the program and provide the correct version of the code. Note: The errors can be syntactical or logical.

#include <stdio.h>

Int main()

{

     Int value [3] = { 0, 0, 0, };               //array declaration

     Int I;

     For (I = 0; i<5; i++)            //step through each element

     {

                    Value [i] = 1;       //assign each element the value of 1

                    Printf(“ value[%d] = %d ”, I, value[i]); //display the array

     }

     Printf(“ ”);

     Return 0;                            //terminate program

}

1.      Providing the correct code from up above adjust the program to hold 10 elements in the array and store the value of 100 in each. Submit the new code for review.

Explanation / Answer

CORRECT CODE:

#include <stdio.h>

void main () {

int n[10]; /* n is an array of 10 integers */
int i,j;
  
for ( i = 0; i < 10; i++ ) {
n[ i ] = 100; /* set element at location i to 100 */
}

/* output each array element's value */
for (j = 0; j < 10; j++ ) {
printf("Element[%d] = %d ", j, n[j] );
}

}

OUTPUT

Hope this has answered your question. Please do not forget to like my answer.