RSS

contoh Program array dinamis dalam format matriks

04 May

#include
#include
#include
#define maksi 10

typedef matrix[maksi][maksi];

void main()
{
int n, x, y;
matrix A, B, C;

cout<<"PROGRAM PENJUMLAHAN MATRIK 3×3 \n";
cout<<"\n\n";

n=3;
cout<<"Nilai Matriks A : \n";
for (x=1; x<=n; x++)
{
for (y=1; y<=n; y++)
{
cout<<"A["<<x<<","<<y<>A[x][y];
}}
cout<<"\nNilai matriks B : \n";
for (x=1; x<=n; x++)
{
for (y=1; y<=n; y++)
{
cout<<"B["<<x<<","<<y<>B[x][y];
}
}

clrscr();
cout<<"\n";
for (x=1; x<=n; x++)
{
for (y=1; y<=n; y++)
{
C[x][y] = A[x][y] + B[x][y];
} }

clrscr();
cout<<"Penjumlahan matriks A dan matriks B : \n";

gotoxy(1, 4);
cout<<" A = ";
for (x=1; x<=n; x++)
{
for (y=1; y<=n; y++)
{
gotoxy(2+4*y,2*x);
cout<<" "<<A[x][y]<<" ";
}
cout<<endl;
}

gotoxy(1, 11);
cout<<" B = ";
for (x=1; x<=n; x++)
{
for (y=1; y<=n; y++)
{
gotoxy(2+4*y,7+2*x);
cout<<" "<<B[x][y]<<" ";
}
cout<<endl;
}

gotoxy(1, 18);
cout<<" C = ";
for (x=1; x<=n; x++)
{
for (y=1; y<=n; y++)

{
gotoxy(1+4*y,14+2*x);
cout<<" "<<A[x][y]<<" ";
} }

gotoxy(17,18);
cout<<" + ";
for (x=1; x<=n; x++)
{
for (y=1; y<=n; y++)
{
gotoxy(17+4*y,14+2*x);
cout<<" "<<B[x][y]<<" ";
} }

gotoxy(33,18);
cout<<" = ";
for (x=1; x<=n; x++)
{
for (y=1; y<=n; y++)
{
gotoxy(32+4*y,14+2*x);
cout<<" "<<C[x][y]<<" ";
} }
getch(); }

 

Tags:

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: