f Tutorial Pemrograman C++ dan Java: Penjumlahan Matrik

Penjumlahan Matrik

#include <iostream>
#include <conio>

void main(){
 typedef int matrik23 [2][3];
matrik23 a,b,c;
int x,y;

    cout<<"masukkan matrik A:\n";
     for (x=0;x<2;x++)
        {for (y=0;y<3;y++)
           {cout<<"a["<<x<<"]["<<y<<"]=";
          cin>>a[x][y];}
          cout<<"\n";}

    cout<<"masukkan matrik B:\n";
     for (x=0;x<2;x++)
        {for (y=0;y<3;y++)
           {cout<<"b["<<x<<"]["<<y<<"]=";
          cin>>b[x][y];}
          cout<<"\n";}


    {cout<<"matrik A:\n";

     for (x=0;x<2;x++)
        {for (y=0;y<3;y++)
             {cout<<a[x][y]<<"\t";}
          cout<<"\n";}
            }
    {cout<<"matrik B:\n";

     for (x=0;x<2;x++)
        {for (y=0;y<3;y++)
             {cout<<b[x][y]<<"\t";}
          cout<<"\n"; }
            }

     for (x=0;x<2;x++)
        {for (y=0;y<3;y++)
        {c[x][y]=a[x][y]+b[x][y];}
         }

    cout<<"matrik C:\n";
      for (x=0;x<2;x++)
        {for (y=0;y<3;y++)
             {cout<<c[x][y]<<"\t";}
          cout<<"\n"; }


getch();}

0 komentar:

Posting Komentar