Проблема возникает при смещении результирующего массива вправо после вставки второго массива в указанной позиции. Обратите внимание, что вращение, круговое или обратное движение не требуется.
#include <stdio.h>
void main() {
int i, n, m, location, b[20], a[20];
printf("Enter the number of elements in first array:\n");
scanf("%d", &m);
printf("Enter the elements of first array : \n");
for (i = 0; i < m; i++) {
scanf("%d", &a[i]);
}
printf("Enter the location to insert second array : \n");
scanf("%d", &location);
printf("Enter the number of elements in second array :\n");
scanf("%d", &n);
printf("Enter the elements of second array : \n");
for (i = 0; i < n; i++) {
scanf("%d", &b[i]);
}
for (i = m; i >= location; i--) {
a[i + n] = a[i];
}
a[location + i] = b[i];
m++;
printf("Resulting array after insertion is : \n");
for (i = 0; i < m; i++) {
printf("%d ", a[i]);
}
printf("\n");
}
После запуска программы. Я понял, что это неправильно.
Enter the number of elements in first array:
3
Enter the elements of first array :
10 20 30
Enter the location to insert second array :
1
Enter the number of elements in second array :
2
Enter the elements of second array :
55 66
Resulting array after insertion is :
10 55 30 20