Question: Program using C. Modify merge.c, the merge function using pointer arithmetic. The function prototype should be the following. Name your program merge2.c. void merge(int n,
Program using C.
Modify merge.c, the merge function using pointer arithmetic. The function prototype should be the following. Name your program merge2.c.
void merge(int n, int *a1, int *a2, int *a3);
Note: This program will be based on whether the required functionality were implemented correctly (using pointer arithmetic) instead of whether it produces the correct output, for the functionality part
The function should use pointer arithmetic not subscripting to visit array elements. In other words, eliminate the loop index variables and all use of the [] operator in the function.
#include
int i; int N;
printf("Please enter the length of the input array: ");
scanf("%d", &N);
int a[N];
int a1[N];
int b[2*N]; printf("Enter %d numbers for the first array: ", N);
for (i = 0; i < N; i++)
scanf("%d", &a[i]); printf("Enter %d numbers for the second array: ", N);
for (i = 0; i < N; i++)
scanf("%d", &a1[i]); merge(N, a, a1, b); printf("Output array:");
for (i = 0; i < 2*N; i++)
printf(" %d", b[i]);printf(" "); return 0;
} void merge(int n, int a1[], int a2[],int a3[]){
int i, j = 0;
for(i = 0; i < n; i++, j+=2) {
a3[j]= a1[i];
a3[j+1] = a2[i];
}
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
