Skip to content

Instantly share code, notes, and snippets.

@anisur3036
Created November 6, 2022 06:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anisur3036/4c8b385d7a84401ab744cd2e729d7abd to your computer and use it in GitHub Desktop.
Save anisur3036/4c8b385d7a84401ab744cd2e729d7abd to your computer and use it in GitHub Desktop.
Divide into two array of one array element and after that merge them again oposite direction
int main() {
/* Enter your code here. Read input from STDIN. Print output to STDOUT */
int N, R, K, i, j, index, boysIndex;
int arr[21];
int arr2[21];
int arr3[21];
int mergeArray[21];
scanf("%d", &N);
for (i = 1; i <= N; i++)
{
scanf("%d", &R);
arr[i] = R;
}
scanf("%d", &K);
index = K;
for(i=1; i<=index;i++) {
arr2[i] = arr[i];
}
boysIndex = N - K;
for(i=1;i<=boysIndex; i++) {
arr3[i] = arr[i + K];
}
//merge 2 array
for(j=1;j<=(N - K); j++) {
//copy element of array 3 to mergeArray
mergeArray[j] = arr3[j];
}
for(j=1;j<=K; j++) {
// copy element of array 2 to merge array but index start from after last index of first copy element
mergeArray[j+K] = arr2[j];
}
//merge 2 array
// i = 1;
// for(j=1; j<=(N - K); j++) {
// mergeArray[i] = arr3[j];
// i++;
// }
// for (j = 1; j <= K; j++)
// {
// mergeArray[i] = arr2[j];
// i++;
// }
for(i=1; i<=N; i++) {
printf("%d ", mergeArray[i]);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment