Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <conio.h>
- #include <time.h>
- #include <stdlib.h>
- #define Mrow 100
- #define Mcol 100
- using namespace std;
- int nhap(int a[3][3])
- {
- int i,j;
- for (i=0;i<3;i++)
- for (j=0;j<3;j++)
- cin>>a[i][j];
- getch();
- }
- int hienthi(int a[3][3])
- {
- int i,j;
- for (i=0;i<3;i++) {
- for (j=0;j<3;j++)
- cout<<a[i][j]<<" ";
- cout<<endl; }
- }
- int ngaunhien(int a[3][3])
- {
- int i,j;
- srand((unsigned)time(NULL));
- for (i=0;i<3;i++){
- for (j=0;j<3;j++)
- a[i][j]=rand()%100;
- }
- }
- int hienthingaunhien(int a[3][3])
- {
- int i,j;
- for (i=0;i<3;i++) {
- for (j=0;j<3;j++)
- cout<<a[i][j]<<" ";
- cout<<endl;
- }
- }
- int nhapvoigiatribatky(int a[Mrow][Mcol],int& m,int& n) //có dấu & để khi truy xuất ở dưới nó sẽ truyền ngược trở lại vào hàm int nhap() nếu không sẽ bị lặp vô hạn.
- {
- int i,j;
- cout<<"Nhap kich thuoc dong & cot:"<<endl;
- cin>>m;
- cin>>n;
- for (i=0;i<m;i++)
- {
- for (j=0;j<n;j++)
- cin>>a[i][j];
- }
- getch();
- }
- int hienthivoigiatribatky(int a[Mrow][Mcol],int& m,int& n)
- {
- int i,j;
- for (i=0;i<m;i++)
- {
- for (j=0;j<n;j++)
- cout<<a[i][j]<<" ";
- cout<<endl;
- }
- }
- int chepdong(int a[Mrow][Mcol],int m,int n)
- //chép dòng k-->h
- {
- int i,j,h,k;
- cout<<"chon dong nguon & dong chep de len:"<<endl;
- cin>>k;
- cin>>h;
- if (k<1 || k>m || h<1 || h>m)
- {
- return(0);
- }
- for (i=0;i<n;i++)
- {
- a[h-1][i]=a[k-1][i];
- }
- for (i=0;i<m;i++)
- {
- for (j=0;j<n;j++)
- cout<<a[i][j]<<" ";
- cout<<endl;
- }
- }
- int chepcot(int a[Mrow][Mcol],int m,int n)
- //chép cột k-->h
- {
- int i,j,h,k;
- cout<<"chon cot nguon & cot chep de len:"<<endl;
- cin>>k;
- cin>>h;
- if (k<1 || k>m || h<1 || h>m)
- {
- return(0);
- }
- for (i=0;i<m;i++)
- {
- a[i][h-1]=a[i][k-1];
- }
- for (i=0;i<m;i++)
- {
- for (j=0;j<n;j++)
- cout<<a[i][j]<<" ";
- cout<<endl;
- }
- }
- int hoandoidong(int a[Mrow][Mcol],int m,int n)
- {
- int i,j,h,k,temp;
- cout<<"chon 2 dong can hoan doi"<<endl;
- cin>>h;
- cin>>k;
- if (k==h) return(0);
- for (i=0;i<n;i++)
- {
- temp=a[k-1][i];
- a[k-1][i]=a[h-1][i];
- a[h-1][i]=temp;
- }
- for (i=0;i<m;i++)
- {
- for (j=0;j<n;j++)
- cout<<a[i][j]<<" ";
- cout<<endl;
- }
- }
- int hoandoicot(int a[Mrow][Mcol],int m,int n)
- {
- int i,j,h,k,temp;
- cout<<"chon 2 cot can hoan doi"<<endl;
- cin>>h;
- cin>>k;
- if (k==h) return(0);
- for (i=0;i<m;i++)
- {
- temp=a[i][k-1];
- a[i][k-1]=a[i][h-1];
- a[i][h-1]=temp;
- }
- for (i=0;i<m;i++)
- {
- for (j=0;j<n;j++)
- cout<<a[i][j]<<" ";
- cout<<endl;
- }
- }
- int loaibodong(int a[Mrow][Mcol],int& m,int n)
- {
- int i,j,k;
- cout<<"nhap dong can loai bo"<<endl;
- cin>>k;
- if (k<0 || k>m) return(0);
- for(i=k-1;i<m-1;i++)
- {
- for(j=0;j<n;j++)
- a[i][j]=a[i+1][j];
- }
- m--;
- for (i=0;i<m;i++)
- {
- for (j=0;j<n;j++)
- cout<<a[i][j]<<" ";
- cout<<endl;
- }
- }
- int loaibocot(int a[Mrow][Mcol],int m,int& n)
- {
- int i,j,k;
- cout<<"nhap cot can loai bo"<<endl;
- cin>>k;
- if (k<0 || k>n) return(0);
- for(i=k-1;i<n-1;i++)
- {
- for(j=0;j<m;j++)
- a[i][j]=a[i][j+1];
- }
- n--;
- for (i=0;i<m;i++)
- {
- for (j=0;j<n;j++)
- cout<<a[i][j]<<" ";
- cout<<endl;
- }
- }
- int main()
- {
- int a[Mrow][Mcol],m,n;
- nhapvoigiatribatky(a,m,n);
- hienthivoigiatribatky(a,m,n);
- //ngaunhien(a);
- //hienthingaunhien;
- //chepdong(a,m,n);
- //chepcot(a,m,n);
- //hoandoidong(a,m,n);
- //hoandoicot(a,m,n);
- //loaibodong(a,m,n);
- //loaibocot(a,m,n);
- getch();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement