Question: For C program, convert the 1-D stencil program from lab_03 to use array reference (B[i]) to access array element instead of using pointers. The C

For C program, convert the 1-D stencil program from lab_03 to use array reference (B[i]) to access array element instead of using pointers. The C program follows these steps: 1) declare two arrays, each has 100 elements, 2) use a for loop to randomly generate 100 integers and store them in one array; 2) use another for loop to do the 1-D stencil and store the result in the other array; Write a main program in C from https://repl.it/languages/c.

#include #include

int main(int argc, char * argv[]) { int i = 0; int j = 0; int N = 100; int M=100; int d = 3; int B[N]; int B2[M]; printf(" ------------------------- 1-D stencil operation -------------------------------------- "); printf("Element values of array B[%d] ", N); for (i=0; i

printf(" Element values of array B2[%d] after 1-D stencil operation on array B ", M); for(j = 0; j < M; j++){ B2[j] = (B[j-1]+B[j]+B[j+1])/3;

printf("%d\t", B2[j]); if ((i+1)%10==0) printf(" "); //go to the next line }

return 0; } I am not sure my code right or wrong please help me check

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!