Please do not use any pointers in the program. Write a program in C that add a r
ID: 3747894 • Letter: P
Question
Please do not use any pointers in the program.
Write a program in C that add a range (by start index and end index) of numbers from array #1 to array #2 at a given position (index) while removing them from array #1.
Example input/output:
Enter the length of the array #1: 8
Enter the elements of the array #1: 9 12 8 41 38 12 67 49
Enter the length of the array #2: 3
Enter the elements of the array #2: 11 27 6
Enter the start and end index of array #1 to be removed: 2 5
Enter the position (index) of the array #2 to be added before: 1
Output array #1: 9 12 67 49
Output array #2: 11 8 41 38 12 27 6
In the main function, declare the input and output arrays for array #1 and array #2, calculate and display the output arrays.
Explanation / Answer
#include<stdio.h>
int main()
{
int i,n,m;
printf("Enter the length of the array #1: ");
scanf("%d",&n);
printf("Enter the elements of the array #1: ");
int arr1[n];
for(i=0;i<n;i++)
scanf("%d",&arr1[i]);
printf("Enter the length of the array #2: ");
scanf("%d",&m);
printf("Enter the elements of the array #2: ");
int arr2[m];
for(i=0;i<m;i++)
scanf("%d",&arr2[i]);
int start,end;
printf("Enter the start and end index of array #1 to be removed: ");
scanf("%d %d",&start,&end);
int index=m+(end-start+1);
int temp[index];
int before,j=0;
printf("Enter the position (index) of the array #2 to be added before: ");
scanf("%d",&before);
for(i=0;i<before;i++)
{
temp[j]=arr2[i];
j++;
}
for(i=start;i<=end;i++)
{
temp[j]=arr1[i];
j++;
}
for(i=before;i<m;i++)
{
temp[j]=arr2[i];
j++;
}
int k=0;
for(i=end+1;i<n;i++)
{
arr1[start+k]=arr1[i];
k++;
}
n=n-(end-start+1);
printf("Output array #1: ");
for(i=0;i<n;i++)
printf("%d ",arr1[i]);
printf(" ");
m=j;
for(i=0;i<m;i++)
{
arr2[i]=temp[i];
}
printf("Output array #2: ");
for(i=0;i<m;i++)
printf("%d ",arr2[i]);
}