Gabung Ke Forum Saya Di 4KA01

Program Sederhana Matriks Ordo 3×3

Kali ini gw sedikit mau membahas tentang Array, nah implementasi nya gw membuat sebuah coding sederhana yaitu Matriks ordo 3×3. perhatikan coding dibawah ini :

Listing_program nya:

#include"iostream.h"
int main()
{
float A[3][3];
float B[3][3];
float C[3][3];
double X[3][3];
int i,j;
float x,n=0;//n is the determinant of A
cout<<"========== Masukan matrix A ==========\n";
for(i=0;i<3;i++)
{ cout<
for(j=0;j<3;j++)
{
cout<<" A["<
<<"]["<<<"]= ";
cin>>A[i][j];
B[i][j]=0;
C[i][j]=0;
}
}
for(i=0,j=0;j<3;j++)
{
if(j==2)
n+=A[i][j]*A[i+1][0]*A[i+2][1];
else if(j==1)
n+=A[i][j]*A[i+1][j+1]*A[i+2][0];
else
n+=A[i][j]*A[i+1][j+1]*A[i+2][j+2];
}
for(i=2,j=0;j<3;j++)
{
if(j==2)
n-=A[i][j]*A[i-1][0]*A[i-2][1];
else if(j==1)
n-=A[i][j]*A[i-1][j+1]*A[i-2][0];
else
n-=A[i][j]*A[i-1][j+1]*A[i-2][j+2];
}
cout<<"\n========== MATRIX A ==============\n";
for(i=0;i<3;i++)
{
cout<
for(j=0;j<3;j++)
{
cout<<" A["<<<"]["<<<"]= "<
}
}
cout<<
cout<<"\n========== Transpos matrix A ==============================\n";
for(i=0;i<3;i++)
{
cout<
for(j=0;j<3;j++)
{
B[i][j]=A[j][i];
cout<<" B["<<<"]["<<<"]= "<
}
}
cout<<
}

1 Komentar:

Anonymous said...

thx bro