Tboy Cá voi
Tổng số bài gửi : 178 Cảm ơn : 413 Danh vọng : 4 Join date : 03/01/2011 Age : 32 Đến từ : TPHCM
| Tiêu đề: Điểm yên ngựa Wed Jun 01, 2011 9:20 pm | |
| | Wed Jun 01, 2011 9:20 pm Điểm yên ngựa | | | - Code:
-
/*======================================= * TIM DIEM YEN NGUA TRONG MA TRAN CAP N * ----------TBOY----------- =========================================*/ #include <stdio.h> #define MAX 100 //******************************************** void Nhap(int A[][MAX],int Cap); void Xuat(int A[][MAX],int Cap); int Mindong(int A[][MAX],int Cap,int Dong); int Maxdong(int A[][MAX],int Cap,int Dong); int Mincot(int A[][MAX],int Cap,int Cot); int Maxcot(int A[][MAX],int Cap,int Cot); void YenNgua(int A[][MAX],int Cap); //******************************************** void main() { int a[MAX][MAX],cap; //Nhap xuat ma tran cap n do { printf("Nhap cap ma tran: "); scanf("%d",&cap); }while(cap<1||cap>MAX); Nhap(a,cap); printf("Ma tran vua nhap: \n"); Xuat(a,cap); //Tim diem yen ngua printf("Diem yen ngua:\n"); YenNgua(a,cap); } //******************************************** void Nhap(int A[][MAX],int Cap) { for(int i=0;i<Cap;i++) for(int j=0;j<Cap;j++) { printf("A[%d][%d]= ",i+1,j+1); scanf("%d",&A[i][j]); } } void Xuat(int A[][MAX],int Cap) { for(int i=0;i<Cap;i++) { for(int j=0;j<Cap;j++) printf("%5d",A[i][j]); printf("\n"); } } int Mindong(int A[][MAX],int Cap,int Dong) //Tra ve cot cua phan tu min trong dong` dang xet { int min=A[Dong][0],cot=0; for(int i=1;i<Cap;i++) if(A[Dong][i]<min) { min=A[Dong][i]; cot=i; } return cot; } int Maxdong(int A[][MAX],int Cap,int Dong) //Tra ve cot cua phan tu max trong dong` dang xet { int max=A[Dong][0],cot=0; for(int i=1;i<Cap;i++) if(A[Dong][i]>max) { max=A[Dong][i]; cot=i; } return cot; } int Mincot(int A[][MAX],int Cap,int Cot) //Tra ve dong cua phan tu min trong cot dang xet { int min=A[0][Cot],dong=0; for(int i=1;i<Cap;i++) if(A[i][Cot]<min) { min=A[i][Cot]; dong=i; } return dong; } int Maxcot(int A[][MAX],int Cap,int Cot) //Tra ve dong cua phan tu max trong cot dang xet { int max=A[0][Cot],dong=0; for(int i=1;i<Cap;i++) if(A[i][Cot]>max) { max=A[i][Cot]; dong=i; } return dong; } void YenNgua(int A[][MAX],int Cap) { int tmp; for(int i=0;i<Cap;i++) { //Xet theo Min Dong, Max Cot tmp=Mindong(A,Cap,i); if(i==Maxcot(A,Cap,tmp)) printf("A[%d][%d]= %d\n",i+1,tmp+1,A[i][tmp]); //Xet theo Max Dong, Min Cot tmp=Maxdong(A,Cap,i); if(i==Mincot(A,Cap,tmp)) printf("A[%d][%d]= %d\n",i+1,tmp+1,A[i][tmp]); } } Tboy
| | | | | |
|