Jumat, 24 Juni 2011

Program C++ Transpose Matriks


At this time himpinan integer given in the form of two-dimensional array and transposing the matrix. Whether we are now we learn to make the algorithms and programs. Of course it is difficult but what if we learn ... hehehehe. Please see the algorithms and source code ... check it out .. n lets try ..!

Algoritma :
Procedure tranpose_array(input : a,m,n ; integer, output : a ; array of integer)
Deklarasi
a[ ]                      : integer of array
m,n,I,j                 : integer
Deskripsi
read(m,n)
if (m != n) then
write(Matriks tidak persegi, tidak ditranspose)
else
for i <= 0 to m do
for j <= 0 to n do
write(a[i][j])
endfor
endfor
endif
//menampilkan matriks setelah ditranspose
for i <= 0 to m do
for j <= 0 to n do
write(a[j][i])
endfor
endfor

Berikut kode programnya :

#include <iostream.h>
#include <conio.h>

void main(){
clrscr();
int a[10][10],m,n,i,j;
cout<<"Masukan jumlah baris : ";
cin>>m;
cout<<"Masukan jumlah kolom : ";
cin>>n;

if (m!=n){
cout<<"Matriks tidak persegi jadi transpose tidak mungkin";}
else {
cout<<"Masukan elemen dari matriks : "<<endl;
for (i=0; i<m; i++){
for (j=0; i<n; i++){
cout<<"Masukan elemen a"<<i+1<<j+1<<":";
cin>>a[i][j];}
}
cout<<"Menampilkan matriks : "<<endl<<endl;
for (i=0; i<m; i++){
for (j=0; j<n; j++){
cout<<a[i][j]<< " ";}
cout<<endl<<endl;
cout<<"Menampilkan matriks setelah ditranspose :"<<endl<<endl;
for (i=0; i<m; i++){
for (j=0; j<n; j++){
cout<<a[j][i]<< " ";
cout<<endl<<endl;}
}
getch();
}


explanation:  
The above program is a program for transposing the data matrix a [i] [j] in turn into a [j] [i] with a method for loop and two-dimensional array. But in the program above there is also a selection process if the matrix is not square then the transpose will not do. But if the square then the iteration process will be conducted and transposing the matrix.

1 komentar:

Elwin Zeva mengatakan...

thx ya, programnya cukup membantu...
tapi kenapa tidak bisa dijalankan kalau baris dan kolom berbeda...

mohon penjelasannya ya.. :)

Poskan Komentar

Template by:

Free Blog Templates