/* Include lib */
#include <stdio.h>

/* Define */
#if 0
#define ARRAY2D_ROW    2
#define ARRAY2D_COL    3

int array_input[ARRAY2D_ROW][ARRAY2D_COL] = {
    /* row 0 */ 1, 2, 3,
    /* row 1 */ 4, 5, 6
};
#else
#define ARRAY2D_ROW    3
#define ARRAY2D_COL    4

int array_input[ARRAY2D_ROW][ARRAY2D_COL] = {
    /* row 0 */ 1,  2,  3,  4,
    /* row 1 */ 5,  6,  7,  8,
    /* row 2 */ 9, 10, 11, 12
};
#endif

/*
 * Rotate array: Rotate array2D 90 degree mean swap row & col to new array.
 * Ex: 1 2      -->     3 1
 *     3 4              4 2
 *
 * Ex: 1 2 3    -->     4 1
 *     4 5 6            5 2
 *                      6 3
 */
#define ROTATE_ARRAY2D_ROW    ARRAY2D_COL
#define ROTATE_ARRAY2D_COL    ARRAY2D_ROW

int array_output[ROTATE_ARRAY2D_ROW][ROTATE_ARRAY2D_COL] = { 0 };
     
/* API */
/* API rotate array2D 90 degree right */
int rotate_array2D_right()
{
    int rcnt, ccnt;
    
    /* Assign output from input with position calculated */
    for (rcnt = 0; rcnt < ROTATE_ARRAY2D_ROW; rcnt++) {
        for (ccnt = 0; ccnt < ROTATE_ARRAY2D_COL; ccnt++) {
            array_output[rcnt][ccnt] = array_input[(ARRAY2D_ROW - 1) - ccnt][rcnt];
            //printf("out[%d][%d] = %d\n", rcnt, ccnt, array_output[rcnt][ccnt]);
        }
    }
    
    return 0;
}

/* Main func interract with user */
int main()
{
    int i, j;
    
    printf("Input array :\n");
    for (i = 0; i < ARRAY2D_ROW; i++) {
        for (j = 0; j < ARRAY2D_COL; j++) {
            printf("%d ", array_input[i][j]);
        }
        printf("\n");
    }
    
    /* Rorate array */
    rotate_array2D_right();
    
    printf("Output array:\n");
    for (i = 0; i < ROTATE_ARRAY2D_ROW; i++) {
        for (j = 0; j < ROTATE_ARRAY2D_COL; j++) {
            printf("%d ", array_output[i][j]);
        }
        printf("\n");
    }

    return 0;
}

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: