This program will be graded based on whether the required fu
This program will be graded based on whether the required functionality were implemented correctly instead of whether it produces the correct output. Modify the program; the insert0 detection function using pointer arithmetic. The function prototype should be the following
void insert0(int n, int *a1, int *a2);
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
void insert0(int n, int a1[], int a2[]);
int main(void)
{
int i;
int N;
printf(\"Please enter the length of the input array: \");
scanf(\"%d\", &N);
int a[N];
int b[2*N];
printf(\"Enter %d numbers for the array: \", N);
for (i = 0; i < N; i++)
scanf(\"%d\", &a[i]);
insert0(N, a, b);
printf(\"Output array:\");
for (i = 0; i < 2*N; i++)
printf(\" %d\", b[i]);
printf(\"\ \");
return 0;
}
void insert0(int n, int a[], int b[])
{
int i, j = 0;
for(i = 0; i < n; i++, j+=2){
b[j]= a[i];
b[j+1] = 0;
}
}
Solution
Please refer below program for highlighted changes.
#include<stdio.h>
void insert0(int n, int *a1, int *a2);
int main(void)
{
int i;
int N;
printf(\"Please enter the length of the input array: \");
scanf(\"%d\", &N);
int a[N];
int b[2*N];
printf(\"Enter %d numbers for the array: \", N);
for (i = 0; i < N; i++)
scanf(\"%d\", &a[i]);
insert0(N, a, b);
printf(\"Output array:\");
for (i = 0; i < 2*N; i++)
printf(\" %d\", b[i]);
printf(\"\ \");
return 0;
}
void insert0(int n, int *a, int *b)
{
int i, j = 0;
for(i = 0; i < n; i++, j+=2){
*(b+j) = *(a+i);
*(b+j+1) = 0;
}
}
OUTPUT:
Please enter the length of the input array: 4
Enter 4 numbers for the array: 1 2 3 4
Output array: 1 0 2 0 3 0 4 0

