标签:
include "stdafx.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#define N 10
void Swap(int *x,int *y);
void Transpose(int a[][N],int n);
void InputMatrix(int a[][N],int n);
void PrintMatrix(int a[][N],int n);
int main()
{
int s[N][N],n;
printf_s("input n:");
scanf_s("%d",&n);
InputMatrix(s,n);
Transpose(s,n);
printf_s("The transposed matrix is :\n");
PrintMatrix(s,n);
system("pause");
return 0;
}
void Swap(int *x,int *y)
{
int temp;
temp = *x;
*x = *y;
*y = temp;
}
void Transpose(int a[][N],int n)
{
int i,j;
for(i = 0;i < n;i++)
{
for(j = i;j < n;j++)
{
Swap(&a[i][j],&a[j][i]);
}
}
}
void InputMatrix(int a[][N],int n)
{
int i,j;
printf_s("input %d*%d matrix:\n",n,n);
for(i = 0;i<n;i++)
{
for(j = 0;j < n; j++)
{
scanf_s("%d",&a[i][j],sizeof(a[i][j]));
}
}
}
void PrintMatrix(int a[][N],int n)
{
int i,j;
for(i = 0;i < n;i++)
{
for(j = 0;i < n;j++)
{
printf_s("%d\t",a[i][j]);
}
printf_s("\n");
}
}
标签:
原文地址:http://www.cnblogs.com/joyclub/p/4423207.html