#include <stdio.h>
#include <iostream.h>
#include <iomanip.h>
class matriks{
friend istream& operator>>(istream&, matriks&);
friend ostream& operator<<(ostream&, matriks&);
public:
void buat_identitas(int);
private:
int banyak;
int A[10][10];
};
void matriks::buat_identitas(int n){
int i,j;
banyak=n;
for(i=0; i<n; i++)
for(j=0;j<n;j++){
if(i==j) {
A[i][j]=1;
continue;
}
A[i][j]=0;
}
}
istream& operator>>(istream& in, matriks& A){
return in;
}
ostream& operator<<(ostream& out, matriks& A){
int i,j;
for(i=0;i<A.banyak;i++)
{
for(j=0;j<A.banyak;j++)
cout <<setw(5)<<A.A[i][j]<<" ";
cout <<endl;
}
return out;
}
int main(){
matriks I;
int banyak_elemen;
cout<< "Jumlah elemen \n"; cin>>banyak_elemen;
cout<<"Matriks Identitasnya : \n";
I.buat_identitas(banyak_elemen);
cout << I;
return 0;
}
0 komentar:
Post a Comment