#include <iostream.h>
#include <conio.h>
#include <stdio.h>
#define Nmaks 10
typedef int matrik[Nmaks][Nmaks];
void main()
{
int n,i,j;
matrik A,B,C,D;
gotoxy(30,1);
cout<<"Program matriks\n";
cout<<"Masukkan jumlah ordo n = ";cin>>n;
cout<<"Masukkan entri matriks A\n";
for (i=1;i<=n;i++)
{
for (j=1;j<=n;j++)
{
cout<<"A["<<i<<","<<j<<"] = ";cin>>A[i][j];
}
}
cout<<"\n";
cout<<"Masukkan entri matriks B \n";
for (i=1;i<=n;i++)
{
for (j=1;j<=n;j++)
{
cout<<"B["<<i<<","<<j<<"] = ";cin>>B[i][j];
}
}
cout<<"\n";
// Proses penjumlahan Matrik C=A+B
for (i=1;i<=n;i++)
{
for (j=1;j<=n;j++)
{
C[i][j]= A[i][j]+B[i][j];
}
}
// Proses pengurangan Matrik D=A-B
for (i=1;i<=n;i++)
{
for (j=1;j<=n;j++)
{
D[i][j]= A[i][j]-B[i][j];
}
}
//proses matrik C
gotoxy(30,3);
cout<<"C = A + B";
gotoxy(30,5);
cout<<"Hsl = ";
for (i=1;i<=n;i++)
{
for (j=1;j<=n;j++)
{
gotoxy(33+3*j, 4+i);
cout<<A[i][j];
}
}
gotoxy(34+(n*3),5);
cout<<" + ";
for (i=1;i<=n;i++)
{
for (j=1;j<=n;j++)
{
gotoxy(n*3+34+(3*j), 4+i);
cout<<B[i][j];
}
}
gotoxy(35+(n*6),5);
cout<<" = ";
for (i=1;i<=n;i++)
{
for (j=1;j<=n;j++)
{
gotoxy(n*6+35+(3*j), 4+i);
cout<<C[i][j];
}
}
//proses matrik C
gotoxy(30,7+n);
cout<<"C = A - B";
gotoxy(30,9+n);
cout<<"Hsl = ";
for (i=1;i<=n;i++)
{
for (j=1;j<=n;j++)
{
gotoxy(33+3*j, 8+n+i);
cout<<A[i][j];
}
}
gotoxy(34+(n*3),9+n);
cout<<" - ";
for (i=1;i<=n;i++)
{
for (j=1;j<=n;j++)
{
gotoxy(n*3+34+(3*j), 8+n+i);
cout<<B[i][j];
}
}
gotoxy(35+(n*6),4+n);
cout<<" = ";
for (i=1;i<=n;i++)
{
for (j=1;j<=n;j++)
{
gotoxy(n*6+35+(3*j), 8+n+i);
cout<<D[i][j];
}
}
getch();
}
Hasil output program:
#include <conio.h>
#include <stdio.h>
#define Nmaks 10
typedef int matrik[Nmaks][Nmaks];
void main()
{
int n,i,j;
matrik A,B,C,D;
gotoxy(30,1);
cout<<"Program matriks\n";
cout<<"Masukkan jumlah ordo n = ";cin>>n;
cout<<"Masukkan entri matriks A\n";
for (i=1;i<=n;i++)
{
for (j=1;j<=n;j++)
{
cout<<"A["<<i<<","<<j<<"] = ";cin>>A[i][j];
}
}
cout<<"\n";
cout<<"Masukkan entri matriks B \n";
for (i=1;i<=n;i++)
{
for (j=1;j<=n;j++)
{
cout<<"B["<<i<<","<<j<<"] = ";cin>>B[i][j];
}
}
cout<<"\n";
// Proses penjumlahan Matrik C=A+B
for (i=1;i<=n;i++)
{
for (j=1;j<=n;j++)
{
C[i][j]= A[i][j]+B[i][j];
}
}
// Proses pengurangan Matrik D=A-B
for (i=1;i<=n;i++)
{
for (j=1;j<=n;j++)
{
D[i][j]= A[i][j]-B[i][j];
}
}
//proses matrik C
gotoxy(30,3);
cout<<"C = A + B";
gotoxy(30,5);
cout<<"Hsl = ";
for (i=1;i<=n;i++)
{
for (j=1;j<=n;j++)
{
gotoxy(33+3*j, 4+i);
cout<<A[i][j];
}
}
gotoxy(34+(n*3),5);
cout<<" + ";
for (i=1;i<=n;i++)
{
for (j=1;j<=n;j++)
{
gotoxy(n*3+34+(3*j), 4+i);
cout<<B[i][j];
}
}
gotoxy(35+(n*6),5);
cout<<" = ";
for (i=1;i<=n;i++)
{
for (j=1;j<=n;j++)
{
gotoxy(n*6+35+(3*j), 4+i);
cout<<C[i][j];
}
}
//proses matrik C
gotoxy(30,7+n);
cout<<"C = A - B";
gotoxy(30,9+n);
cout<<"Hsl = ";
for (i=1;i<=n;i++)
{
for (j=1;j<=n;j++)
{
gotoxy(33+3*j, 8+n+i);
cout<<A[i][j];
}
}
gotoxy(34+(n*3),9+n);
cout<<" - ";
for (i=1;i<=n;i++)
{
for (j=1;j<=n;j++)
{
gotoxy(n*3+34+(3*j), 8+n+i);
cout<<B[i][j];
}
}
gotoxy(35+(n*6),4+n);
cout<<" = ";
for (i=1;i<=n;i++)
{
for (j=1;j<=n;j++)
{
gotoxy(n*6+35+(3*j), 8+n+i);
cout<<D[i][j];
}
}
getch();
}
Hasil output program:
0 comments:
Post a Comment