920 人解决,954 人已尝试。
1197 份提交通过,共有 3162 份提交。
0.7 EMB 奖励。
单点时限: 2.0 sec
内存限制: 256 MB
定义函数 transpose 转置一个 n 阶方阵。元素类型是 int。
只需按要求写出函数定义,并使用给定的测试程序测试你所定义函数的正确性。
测试正确后,将函数定义提交到系统,不要提交主函数代码。
#include <stdio.h>
#include <stdlib.h>
#define N 10
/********** Specification of transpose **********/
void Transpose(void *a, int n)
/* PreCondition:
a is beginning address of a square matrix, n is the number of rows for the matrix, no more than 80.
PostCondition:
the matrix is transposed
*/
{
//TODO
}
/***************************************************************/
int main()
{
int *a, n, i;
scanf("%d", &n);
a = (int *)malloc(n * n * sizeof(int));
for (i = 0; i < n * n; i++)
scanf("%d", a + i);
Transpose(a, n);
for (i = 0; i < n * n; i++)
{
printf("%d ", a[i]);
if ((i + 1) % n == 0)
printf("\n");
}
free(a);
return 0;
}
2 123 456 789 0
123 789 456 0