Algoritma dan Program C++ Matriks
program transpose matriks c++ |
Algoritma
Deklarasi :
a[10][10] : int
baris,kolom : int
i,j : int
Deskripsi :
Baca (baris)
Baca (kolom)
for(i=0;i<baris;i++)
{
for(j=0;j<kolom;j++)
{
Tulis a[i][j]
}
}
Transpose :
for(i=0;i<baris;i++)
{
for(j=0;j<kolom;j++)
{
Transpose a[j][i]
}
}
Program C++
//TRANSPOSE MATRIKS
#include <cstdlib>
#include <iostream>
using namespace std;
int main(int argc, char *argv[])
{
int a[10][10];
int baris;
int kolom;
int i,j;
cout<<"Masukkan Jumlah Baris: ";
cin>>baris;
cout<<"Masukkan Jumlah kolom: ";
cin>>kolom;
cout<<endl<<"Elemen matriks: "<<endl;
for(i=0;i<baris;i++)
{
for(j=0;j<kolom;j++)
{
cout<<"Masukkan Elemen : "<<"["<<i+1<<"]"<<"["<<j+1<<"] : ";
cin>>a[i][j];
}
cout<<endl;
}
cout<<"\nMatriks: "<<endl<<endl;
for(i=0; i<baris; i++)
{
for(j=0; j<kolom; j++)
{
cout<<a[i][j]<<" ";
}
cout<<endl;
}
cout<<"\nTranspose Matriks: "<<endl<<endl;
for(i=0; i<baris; i++)
{
for(j=0; j<kolom; j++)
{
cout<<a[j][i]<<" ";
}
cout<<endl;
}
return 0;
}
Komentar
Posting Komentar