This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
int main(void) | |
{ | |
int n = 4; // size of rectangular 2d array | |
int array[4][4] = { | |
{ 1, 2, 3, 4 }, | |
{ 5, 6, 7, 8 }, | |
{ 9, 10, 11, 12 }, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
/* rotate array to the left by n elements */ | |
void rotate_array_left(int array[], int size, int n) { | |
int *tmp_array = (int*)malloc(n * sizeof(int)); | |
memcpy(tmp_array, array, n * sizeof(int)); // temporarily save leading n elements | |
memmove(array, array + n, (size - n) * sizeof(int)); // shift array to the left | |
memmove(array + size - n, tmp_array, n * sizeof(int)); // append saved | |
free(tmp_array); |