C语言——行列倒置函数实现

来源:互联网 发布:淘宝买家怎么修改评价 编辑:程序博客网 时间:2024/06/06 10:04

今天在网上看到一段行列倒置的函数,代码如下:

// test.cpp : 定义控制台应用程序的入口点。//#include "stdafx.h"#include <stdio.h>#include <stdlib.h>#include <string.h>int main(int argc, char* argv[]){char test[16] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15 };printf("test\r\n");for (int i = 0; i < 4; i++) {for (int j = 0; j < 4; j++) {printf("%d,",test[4*i+j]);}printf("\n");}char *out1 = (char *)malloc(16*sizeof(char));printf("out1:行列倒置\r\n");for (int i = 0; i < 4; i++) {for (int j = 0; j < 4; j++) {out1[4*i+j] = test[i+4*j];printf("%d,",out1[4*i+j]);}printf("\n");}//释放内存free(out1);getchar();return 0;}

结果如下图:


原创粉丝点击