Dev C++
source code :
#include<iostream>
#include<conio.h>
using namespace std;
int main()
{
int matrix[3][3];
int i,j;
for(i=0;i<=2;i++)
{
for(j=0;j<=2;j++)
{
cout<<"Masukkan Nilai Angka Pada Baris Ke "<<i<<" dan Kolom Ke "<<j<<" : ";
cin>>matrix[i][j];
}
cout<<endl;
}
for(i=0;i<=2;i++)
{
for(j=0;j<=2;j++)
{
cout<<matrix[i][j]<<" ";
}
cout<<endl;
}
return (0);
}
outputnya :
Dev C++
source code :
#include <iostream>
#include <conio.h>
#include <stdio.h>
using namespace std;
main()
{
//deklarasi
int matrixa[3][3],matrixb[3][3],matrixc[3][3];
int i,j;
char opr;
//input nilai matriks ke-1 dari baris dan kolom
for(i=1;i<=2;i++){
for(j=1;j<=2;j++){
cout<<"Masukkan matriks(1) nilai baris ke-"<<i<<" kolom ke-"<<j<<" : ";cin>>matrixa[i][j];
}
cout<<endl;
}
//output matriks ke-1
for(i=1;i<=2;i++){
for(j=1;j<=2;j++){
cout<<matrixa[i][j]<<"\t";
}
cout<<endl;
}
//input nilai matriks ke-2 dari baris dan kolom
for(i=1;i<=2;i++){
for(j=1;j<=2;j++){
cout<<"Masukkan matriks(2) nilai baris ke-"<<i<<" kolom ke-"<<j<<" : ";cin>>matrixb[i][j];
}
cout<<endl;
}
//output matriks ke-2
cout<<endl;
for(i=1;i<=2;i++){
for(j=1;j<=2;j++){
cout<<matrixb[i][j]<<"\t";
}
cout<<endl;
}
//Input Operator
cout<<"Pilih Operator +,- :";cin>>opr;
//switching operator
for(i=1;i<=2;i++){
for(j=1;j<=2;j++){
switch(opr){
case '+' : matrixc[i][j] = matrixa[i][j] + matrixb[i][j];
break;
case '-' : matrixc[i][j] = matrixa[i][j] - matrixb[i][j];
break;
default:
cout<<"keyword yang anda masukkan salah/tidak terdaftar";
}
//Output Hasil matriks dari Operator
cout<<matrixc[i][j]<<"\t";
}
cout<<endl;
}
getch();
return 0;
}
outputnya :
Dev C++
source code :
int main ()
{
int matriks1[2][3];
int matriks2[2][3];
int perkalian[2][3];
int transpose[3][2];
int baris,kolom;
cout<<"-------------------\n";
cout<<" Matriks Pertama \n";
cout<<"-------------------\n";
for (baris=0;baris<2;baris++)
{
for (kolom=0;kolom<3;kolom++)
{
cout<<"Masukan Angka ["<<baris<<"] ["<<kolom<<"] = ";
cin>>matriks1[baris][kolom];
}
cout<<endl;
}
for (baris=0;baris<2;baris++)
{
for (kolom=0;kolom<3;kolom++)
{
cout<<matriks1[baris][kolom]<<" ";
}
cout<<endl;
}
cout<<"------------------\n";
cout<<" Matriks Kedua \n";
cout<<"------------------\n";
for (baris=0;baris<2;baris++)
{
for (kolom=0;kolom<3;kolom++)
{
cout<<"Masukan Angka ["<<baris<<"] ["<<kolom<<"] = ";
cin>>matriks2[baris][kolom];
}
cout<<endl;
}
for (baris=0;baris<2;baris++)
{
for (kolom=0;kolom<3;kolom++)
{
cout<<matriks2[baris][kolom]<<" ";
}
cout<<endl;
}
cout<<" Matriks yang di Transpose \n";
cout<<"----------------------------------\n";
for(kolom=0;kolom<3;kolom++)
{
for(baris=0;baris<2;baris++)
{
transpose[kolom][baris]=matriks2[baris][kolom];
cout<<transpose[kolom][baris]<<" ";
}
cout<<endl;
}
cout<<"------------------------------\n";
cout<<" Hasil Perkalian [2]x[2] \n";
cout<<"------------------------------\n";
for (baris=0;baris<2;baris++)
{
for (kolom=0;kolom<2;kolom++)
{
perkalian[0][0]=matriks1[0][0]*transpose[0][0]+matriks1[0][1]*transpose[1][0]+matriks1[0][2]*transpose[2][0];
perkalian[0][1]=matriks1[0][0]*transpose[0][1]+matriks1[0][1]*transpose[1][1]+matriks1[0][2]*transpose[2][1];
perkalian[1][0]=matriks1[1][0]*transpose[0][0]+matriks1[1][1]*transpose[1][0]+matriks1[1][2]*transpose[2][0];
perkalian[1][1]=matriks1[1][0]*transpose[0][1]+matriks1[1][1]*transpose[1][1]+matriks1[1][2]*transpose[2][1];
cout<<perkalian[baris][kolom]<<" ";
}
cout<<endl;
}
}
outpunya :
Tidak ada komentar:
Posting Komentar