sumber gambar : sdtimes.com
#include <iostream> using namespace std; int main() { int a[10][10], trans[10][10], r, c, i, j; cout << "Masukkan baris dan kolom matriks: "<<endl; cout << "baris :";cin >> r; cout << "kolom :";cin >> c; cout << endl << "Masukkan elemen-elemen ke dalam matriks: " << endl; for(i = 0; i < r; ++i) for(j = 0; j < c; ++j) { cout << "Masukkan elemen a" << i + 1 << j + 1 << ": "; cin >> a[i][j]; } cout << endl << "Hasil input ke matriks: " << endl; for(i = 0; i < r; ++i) for(j = 0; j < c; ++j) { cout << " " << a[i][j]; if(j == c - 1) cout << endl << endl; } for(i = 0; i < r; ++i) for(j = 0; j < c; ++j) { trans[j][i]=a[i][j]; } cout << endl << "Hasil tranportasi matriks: " << endl; for(i = 0; i < c; ++i) for(j = 0; j < r; ++j) { cout << " " << trans[i][j]; if(j == r - 1) cout << endl << endl; } return 0; }
Dan hasil contoh program ini adalah sebagai berikut :
Sumber Pustaka : programiz.com
0 komentar: