Best writers. Best papers. Let professionals take care of your academic papers

Order a similar paper and get 15% discount on your first order with us
Use the following coupon "FIRST15"
ORDER NOW

Write short program that uses a for loop to populate an array

Write short program that uses a for loop to populate an array. The array can store up to 10 integers.

Modify the code slightly to create bug that would prevent the code from compiling or even better from running correctly.

Be sure to describe what the code is designed to do.

The following code needs to be corrected and explain what was corrected:

/*Michael Williams */

/*02/27/2018 */

/* loops.c */

/* Program populates array with numbers 1-10 and calculates sum of all items */

#include <stdio.h>

int main()

{

int ary[10];

int i, sum;

for (i = 0; i < 10; i++){

ary[i] = i + 1;

}

for (i = 1; i <= 10; i++){

ary[i] = i;

}

for (i = 0, i < 10, i++){

ary[i] = i + 1;

}

/* Print ary content and calculate sum */

sum = 0;

for (i = 0; i < 10; i++){

printf(“%d “,ary[i]);

sum = sum + ary[i];

}

/* Print sum */

printf(“\nsum = %d\n”, sum);

return 0;

}

 
Looking for a Similar Assignment? Order now and Get 10% Discount! Use Coupon Code "Newclient"