sapxepmang
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#define max 100
int xuat(int a[max][max],int n)
{
int i,j;
for(i=1;i<=n;i++)
{ printf("
");
for(j=1;j<=n;j++)
printf("%4d",a[i][j]);}
}
void sxptlonnhat(int p[max][max],int n)
{
int i,j,tg;
for(i=1;i<=n;i++){
for(j=1;j<=n;j++){
if (p[i][j]>p[i][i]){
tg=p[i][i];
if (p[i][j]>p[i][i]){
p[i][i]=p[i][j];
p[i][j]=tg;}
}
}
}
printf("
sap xep pt lon nhat:
");
for(i=1;i<=n;i++)
{ printf("
");
for(j=1;j<=n;j++)
printf("%4d",p[i][j]);}
}
void sxduongcheochinh(int k[max][max],int n)
{
int i,j,t;
for(i=1;i<=n;i++)
for(j=i+1;j<=n;j++)
if(k[i][i]>k[j][j])
{
t=k[i][i];
k[i][i]=k[j][j];
k[j][j]=t;
}
printf("
sap xep theo duong cheo chinh : ");
for(i=1;i<=n;i++)
{ printf("
");
for(j=1;j<=n;j++)
printf("%4d",k[i][j]);}
}
void chuyensangmotchieu(int l[max][max],int n)
{
int m,j,i;
int b[10000];
m=1;
for(i=1;i<=n;i++)
for(j=1;j<=n;j++){
b[(i-1)*n+j]=l[i][j];
m+=1;
}
printf("
mang 1 chieu la:
");
for(i=1;i<=n*n;i++)
printf("%d",b[i]);
}
void main()
{
int a[max][max],p[max][max],k[max][max],l[max][max];
int n,i,j;
printf("nhap so hang va cot n= ");
scanf("%d",&n);
for(i=1;i<=n;i++)
for (j=1;j<=n;j++)
{
printf("
a[%d][%d]=",i,j);
scanf("%d",&a[i][j]);
p[i][j]=a[i][j];
k[i][j]=a[i][j];
l[i][j]=a[i][j];
}
printf("ma tran vua nhap:
");
xuat(a,n);
sxptlonnhat(p,n);
sxduongcheochinh(k,n);
chuyensangmotchieu(l,n);
}
Bạn đang đọc truyện trên: Truyen247.Pro