11 March 2012

Transpose Matriks

Berikut ini merupakan contoh program sederhana untuk transpose matriks dengan menggunakan array 2 dimensi di pemrograman C++.

Tampilan :
















Script :
#include<iostream.h>
#include<conio.h>
#include<stdlib.h>

void main(){
  while(true){
    system("cls");
    int x=0;
    int y=0;
    int array[9][9];

    cout<<"Input 2 numbers : ";
    cin>>x>>y;
    cout<<"\n";

    if (x>=10 || x==0 || y>=10 || y==0){
      cout<<"MUST > 0 AND < 10 BROOO..."<<endl;
      getch();
    }

    else {
      for (int i=0; i<x; i++){
        for (int j=0; j<y; j++){
          cout<<"nilai array["<<i<<"]["<<j<<"] : ";
          cin>>array[i][j];
        }
      }

      cout<<"\nNormal Matriks  :"<<endl;
      for (int k=0; k<x; k++){
        for (int l=0; l<y; l++){
          cout<<array[k][l]<<"  ";
        }
        cout<<endl;
      }

      cout<<"\nTranspose Matriks  :"<<endl;
      for (int m=0; m<y; m++){
        for (int n=0; n<x; n++){
          cout<<array[n][m]<<"  ";
        }
        cout<<endl;
      }
      getche();
    } 
  }
}
Load disqus comments

2 comments