Senin, 29 Desember 2014

Program c++ Pertambahan Matriks

#include<iostream>
#include<conio.h>
#include<iomanip>
using namespace std;
int i,j,baris, kolom,m1[10][10],m2[10][10],hasil[10][10];
int main()
{
    cout<<"OPERASI PENJUMLAHAN MATRIK"<<endl;
    cout<<"__________________________"<<endl;
    do
{

cout<<"Jumlah Baris=";cin>>baris;
cout<<"Jumlah Kolom=";cin>>kolom;
}

while ((baris>10) ||(kolom>10));
while (kolom>10);
cout<<"matrik A"<<endl;
for (i=0;i<baris;i++)
for(j=0;j<kolom;j++)
{
    cout<<"Data["<<i<<","<<j<<"]=";
    cin>>m1[i][j];
}

cout<<"\n matrik B\n";
for(i=0;i<baris;i++)
for(j=0;j<kolom;j++)
{
cout<<"data["<<i<<","<<j<<"]=";
cin>>m2[i][j];
}
for (i=0; i<baris;i++)
for(j=0;j<kolom;j++)
hasil[i][j]=m1[i][j]+ m2[i][j];
cout<<"\n Hasilnya...\n";
cout<<"matrix A + matrik B =matrik C";
for(i=0;i<baris;i++)
{
    cout<<"\n";
    for(j=0;j<kolom;j++)
    cout<<setw(4)<<m1[i][j];
    cout<<"   ";
    for(j=0;j<kolom;j++)
    cout<<setw(4)<<m2[i][j];
    cout<<"   ";
    for(j=0;j<kolom;j++)
    cout<<setw(4)<<hasil[i][j];
    cout<<"\n";
   
}
}

Tidak ada komentar:

Posting Komentar