#include <stdio.h> #include <stdlib.h> void main(void) { int Upper[5][5] = { 3, 9, 1, 4, 7, 0, 5, 2, 5, 8, 0, 0, 5, 6, 4, 0, 0, 0, 1, 7, 0, 0, 0, 0, 9 }; int RowMajor[15]; int Index; int i, j; printf("Two Dimensional upper triangle array:\n"); for(i = 0; i < 5; i++) { for(j = 0; j < 5; j++) printf("%3d", Upper[i][j]); printf("\n"); } for(i = 0; i < 5; i++) for(j = 0; j < 5; j++) if(i <= j) { Index = (11 - i) * i/2 + (j - i); RowMajor[Index] = Upper[i][j]; } printf("\n"); printf("Row Major one dimensional array:\n"); for(i= 0; i < 15; i++) printf("%3d", RowMajor[i]); printf("\n"); }
原文:https://www.cnblogs.com/lifelessfaultless/p/9292174.html