Membuat program Matrix :
1. Penjumlahan dua buah matriks
2. Pengurangan dua buah matriks
#include <conio.h>
#include <iostream.h>
#include <stdio.h>
#include <iomanip.h>
main()
{
int a,b;
int matrix1[2][2];
int matrix2[2][2];
int matrix3[2][2];
cout<<" **Matrix** "<<endl;
cout<<""<<endl;
//inputan matrix1
for(a=0;a<=1;a++)
{
for(b=0;b<=1;b++)
{
cout<<" Masukkan nilai ke - "<<a<<" "<<b<<" ";
cin>>matrix1[a][b];
}
}
//outputan matrix1
cout<<"\n Matrix1 \n";
for(a=0;a<=1;a++)
{
for(b=0;b<=1;b++)
{
cout<<setiosflags(ios::left)<<setw(3)<<matrix1[a][b];
}
cout<<"\n";
}
cout<<"\n";
//inputan matrix2
for(a=0;a<=1;a++)
{
for(b=0;b<=1;b++)
{
cout<<" Masukkan nilai ke - "<<a<<" "<<b<<" ";
cin>>matrix2[a][b];
}
}
//outputan matrix2
cout<<"\n Matrix2 \n";
for(a=0;a<=1;a++)
{
for(b=0;b<=1;b++)
{
cout<<setiosflags(ios::left)<<setw(3)<<matrix2[a][b];
}
cout<<"\n";
}
//penjumlahan matrix1 + matrix2
for(a=0;a<=1;a++)
{
for(b=0;b<=1;b++)
{
matrix3[a][b]=matrix1[a][b]+matrix2[a][b];
}
}
cout<<"\n Penjumlahan Matrix \n";
for(a=0;a<=1;a++)
{
for(b=0;b<=1;b++)
{
cout<<setiosflags(ios::left)<<setw(3)<<matrix3[a][b];
}
cout<<"\n";
}
//pengurangan matrix1 - matrix2
for(a=0;a<=1;a++)
{
for(b=0;b<=1;b++)
{
matrix3[a][b]=matrix1[a][b]-matrix2[a][b];
}
}
cout<<"\n Pengurangan Matrix \n";
for(a=0;a<=1;a++)
{
for(b=0;b<=1;b++)
{
cout<<setiosflags(ios::left)<<setw(3)<<matrix3[a][b];
}
cout<<"\n";
}
getch();
}
1. Penjumlahan dua buah matriks
2. Pengurangan dua buah matriks
#include <conio.h>
#include <iostream.h>
#include <stdio.h>
#include <iomanip.h>
main()
{
int a,b;
int matrix1[2][2];
int matrix2[2][2];
int matrix3[2][2];
cout<<" **Matrix** "<<endl;
cout<<""<<endl;
//inputan matrix1
for(a=0;a<=1;a++)
{
for(b=0;b<=1;b++)
{
cout<<" Masukkan nilai ke - "<<a<<" "<<b<<" ";
cin>>matrix1[a][b];
}
}
//outputan matrix1
cout<<"\n Matrix1 \n";
for(a=0;a<=1;a++)
{
for(b=0;b<=1;b++)
{
cout<<setiosflags(ios::left)<<setw(3)<<matrix1[a][b];
}
cout<<"\n";
}
cout<<"\n";
//inputan matrix2
for(a=0;a<=1;a++)
{
for(b=0;b<=1;b++)
{
cout<<" Masukkan nilai ke - "<<a<<" "<<b<<" ";
cin>>matrix2[a][b];
}
}
//outputan matrix2
cout<<"\n Matrix2 \n";
for(a=0;a<=1;a++)
{
for(b=0;b<=1;b++)
{
cout<<setiosflags(ios::left)<<setw(3)<<matrix2[a][b];
}
cout<<"\n";
}
//penjumlahan matrix1 + matrix2
for(a=0;a<=1;a++)
{
for(b=0;b<=1;b++)
{
matrix3[a][b]=matrix1[a][b]+matrix2[a][b];
}
}
cout<<"\n Penjumlahan Matrix \n";
for(a=0;a<=1;a++)
{
for(b=0;b<=1;b++)
{
cout<<setiosflags(ios::left)<<setw(3)<<matrix3[a][b];
}
cout<<"\n";
}
//pengurangan matrix1 - matrix2
for(a=0;a<=1;a++)
{
for(b=0;b<=1;b++)
{
matrix3[a][b]=matrix1[a][b]-matrix2[a][b];
}
}
cout<<"\n Pengurangan Matrix \n";
for(a=0;a<=1;a++)
{
for(b=0;b<=1;b++)
{
cout<<setiosflags(ios::left)<<setw(3)<<matrix3[a][b];
}
cout<<"\n";
}
getch();
}
Tampilan Output :
Tidak ada komentar:
Posting Komentar