Question: Provide an improved C implementation of the code that is provided. Build, run and test your program. (no global variable)(code in C language only) code
Provide an improved C implementation of the code that is provided. Build, run and test your program. (no global variable)(code in C language only)
code :
#include
void setArray(int A[], int size){ for (int i =0; i < size; i++) { A[i] = i; } }
void sumArray(int B[], int size, int *sum) { for (int i =0; i < size; i++) { *sum += B[i]; } }
void printArray(int C[], int sum, int size){ for (int i =0; i < size; i++) { printf("%d ", C[i] ); }
printf(" ");
printf("sum is %d ", sum); }
int main() { const int size = 10; int B[size], sum = 0; setArray(B, size);
sumArray(B, size);
printArray(B, sum, size);
return 0; }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
