I need some assistence with editing this C program. Any help is appreciated. 1.
ID: 3926873 • Letter: I
Question
I need some assistence with editing this C program. Any help is appreciated.
1. (30 points) Note: This program will be graded based on whether the required functionality wereimplemented correctly instead of whether it produces the correct output, for the functionality part(80% of the grade).
Modify insert.c (attached, Project 2, #1), the insert0 detection function using pointer arithmetic.The function prototype should be the following. Name your program insert2.c.
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 <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;
}
}
Explanation / Answer
#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;
}
}