五個一維數組如果轉化為一個二維數組(用c語言來實現(xiàn))
已知五個一維數組:a[8]={1,2,3,4,5,6,7,8}b[8]={2,3,4,5,6,7,8,9}c[8]={3,4,5,6,7,8,1,2}d[8]={4,5,6,7,8,1,2,3}e[8]={5,6,7,8,3,5,7,5}想要得到新的二維數組是:f[8][5]={{1,2,4,3,5},{2,3,4,5,6},{3,4,5,6,7},{4,5,6,7,8},{5,6,7,8,3},{,6,7,8,1,5},{7,8,1,2,7},{8,9,2,3,5}}用c語言如何實現(xiàn)詳細說明:新的二維數組8行5列第一列二維數組的元素{1,2,4,3,5}分別對應已知五個一維數組的第一個元素第二列二維數組的元素{2,3,4,5,6}分別對應已知五個一維數組的第二個元素以此類推...............................................第八列二維數組的元素{8,9,2,3,5}分別對應已知五個一維數組的第八個元素
簡單的一個循環(huán)就可以實現(xiàn)////防重復3243685983976984375698326832587326587326598326532932564365332593259864385298359832587432658732154825679068709765873642156843576283435:
#include <stdio.h>int main(){int a[8] = { 1, 2, 3, 4, 5, 6, 7, 8 };int b[8] = { 2, 3, 4, 5, 6, 7, 8, 9 };int c[8] = { 3, 4, 5, 6, 7, 8, 1, 2 };int d[8] = { 4, 5, 6, 7, 8, 1, 2, 3 };int e[8] = { 5, 6, 7, 8, 3, 5, 7, 5 };int f[8][5];int i,j;for(i=0; i<8; i++) {f[i][0] = a[i];f[i][1] = b[i];f[i][2] = c[i];f[i][3] = d[i];f[i][4] = e[i];}///輸出結果for(i=0; i<8; i++) {for(j = 0; j < 5; j++)printf("%2d", f[i][j]);printf("");}return 0;}
測試結果