#include <cstdlib>
#include <iostream>
#include <iomanip>
using namespace std;
int main(int argc, char *argv[])
{int baris, kolom;
cout<<" ------------------------"<<endl;
cout<<"|Operasi Diagonal Matriks|"<<endl;
cout<<" ------------------------"<<endl;
cout<<"Jumlah Baris : "; cin>>baris;
cout<<"Jumlah Kolom : "; cin>>kolom;
int matrix[baris][kolom];
if(baris==kolom){
cout<<"Matriks "<<endl;
for(int i=0;i<baris;i++){
for(int j=0;j<kolom;j++){
cout<<"Masukan nilai ["<<i<<", "<<j<<"] = ";
cin>>matrix[i][j];
}
}
cout<<"Matriks \n"<<endl;
for(int i=0;i<baris;i++){
for(int j=0;j<kolom;j++)
cout<<setw(4)<<matrix[i][j];
cout<<" ";
cout<<endl;
}
cout<<endl;
for(int i=0;i<baris;i++){
for(int j=0;j<kolom;j++) {
if(i!=j){
if(matrix[i][j]!=0){
cout<<"Bukan Matrix diagonal"<<endl;
return 0;
}
}
}
cout<<"matriks diagonal";
}
}
else {
cout<<"bukan matriks diagonal "<<endl;
return 0;}
system("PAUSE");
return EXIT_SUCCESS;
}
Read more ...»
#include <iostream>
#include <iomanip>
using namespace std;
int main(int argc, char *argv[])
{int baris, kolom;
cout<<" ------------------------"<<endl;
cout<<"|Operasi Diagonal Matriks|"<<endl;
cout<<" ------------------------"<<endl;
cout<<"Jumlah Baris : "; cin>>baris;
cout<<"Jumlah Kolom : "; cin>>kolom;
int matrix[baris][kolom];
if(baris==kolom){
cout<<"Matriks "<<endl;
for(int i=0;i<baris;i++){
for(int j=0;j<kolom;j++){
cout<<"Masukan nilai ["<<i<<", "<<j<<"] = ";
cin>>matrix[i][j];
}
}
cout<<"Matriks \n"<<endl;
for(int i=0;i<baris;i++){
for(int j=0;j<kolom;j++)
cout<<setw(4)<<matrix[i][j];
cout<<" ";
cout<<endl;
}
cout<<endl;
for(int i=0;i<baris;i++){
for(int j=0;j<kolom;j++) {
if(i!=j){
if(matrix[i][j]!=0){
cout<<"Bukan Matrix diagonal"<<endl;
return 0;
}
}
}
cout<<"matriks diagonal";
}
}
else {
cout<<"bukan matriks diagonal "<<endl;
return 0;}
system("PAUSE");
return EXIT_SUCCESS;
}