// C Program to shuffle a given Aay #include #include #include // A utility function to print an Aay void printArray (int A[], int n) { int i; for (i = 0; i < n; i++) printf(\"%d \", A[i]); printf(\"\ \"); } int* shuffle(int A[], int B[]) { int n1 = 5; int n2 = 2; int i = 0, j = 0, k = 0; int *C; C = (int*)malloc(7 * sizeof(int)); // Merging starts while (i < n1 && j < n2) { if (k%2 == 0) { C[k] = A[i]; i++; k++; } else { C[k] = B[j]; k++; j++; } } /* elements in array \'A\' are still remaining where as the array \'B\' is exhausted */ while (i < n1) { C[k] = A[i]; i++; k++; } /* elements in array \'B\' are still remaining where as the array \'A\' is exhausted */ while (j < n2) { C[k] = B[j]; k++; j++; } return C; } int main() { int A[] = {1, 2, 3, 4, 5}; int B[] = {10, 20}; int n1 = 5; int n2 = 2; int nC = 7; int *C; C = (int*)malloc(7 * sizeof(int)); printf(\"Array A: \"); printArray(A, n1); printf(\"Array B: \"); printArray(B, n2); C = shuffle (A, B); printf(\"\ Shuffled: \"); printArray(C,nC); return 0; } /* output: Array A: 1 2 3 4 5 Array B: 10 20 Shuffled: 1 10 2 20 3 4 5 */ Solution // C Program to shuffle a given Aay #include #include #include // A utility function to print an Aay void printArray (int A[], int n) { int i; for (i = 0; i < n; i++) printf(\"%d \", A[i]); printf(\"\ \"); } int* shuffle(int A[], int B[]) { int n1 = 5; int n2 = 2; int i = 0, j = 0, k = 0; int *C; C = (int*)malloc(7 * sizeof(int)); // Merging starts while (i < n1 && j < n2) { if (k%2 == 0) { C[k] = A[i]; i++; k++; } else { C[k] = B[j]; k++; j++; } } /* elements in array \'A\' are still remaining where as the array \'B\' is exhausted */ while (i < n1) { C[k] = A[i]; i++; k++; } /* elements in array \'B\' are still remaining where as the array \'A\' is exhausted */ while (j < n2) { C[k] = B[j]; k++; j++; } return C; } int main() { int A[] = {1, 2, 3, 4, 5}; int B[] = {10, 20}; int n1 = 5; int n2 = 2; int nC = 7; int *C; C = (int*)malloc(7 * sizeof(int)); printf(\"Array A: \"); printArray(A, n1); printf(\"Array B: \"); printArray(B, n2); C = shuffle (A, B); printf(\"\ Shuffled: \"); printArray(C,nC); return 0; } /* output: Array A: 1 2 3 4 5 Array B: 10 20 Shuffled: 1 10 2 20 3 4 5 */.