Searching...

Contoh perkalian matrik pada Visual C++

Contoh perkalian matrik pada Visual C++

#include "stdafx.h"

#include <stdio.h>
#include <conio.h>
#include <iostream>
#include <iomanip>
//---------------------------untuk gotoxy --------------------------
#include <windows.h>
 void gotoxy(int x, int y)
 {
 COORD coord;
 coord.X = x; coord.Y = y;
 SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
 }

using std::cout;
using std::endl;
using namespace std;
#define nmaks 10
typedef int matrik[nmaks][nmaks];

int main()
{
int n,i,j;
                matrik A,B,C;
                cout<<"Program Penjumlahan Matrik A 3X3 dan B 3X3"<<endl;
                cout<<endl;
                n=3;
                cout<<"Masukan Nilai-Nilai Matrik A"<<endl;
                for (i=1; i<=n; i++)
                {
                   for (j=1; j<=n; j++)
                   {
                    cout<<"A["<<i<<","<<j<<"] = " ;
                    cin>>A[i][j];
                   }

    }

                system("CLS");
                cout<<"Nama : Angga Lisdiyanto"<<endl;
                cout<<"NIM  : 111010534"<<endl;
    cout<<"Masukan Nilai-Nilai Matrik B"<<endl;
    for (i=1; i<=n; i++)
                {
                   for (j=1; j<=n; j++)
                   {
                                   cout<<"B["<<i<<","<<j<<"] = " ;
                       cin>>B[i][j];
                   }
                 }

//proses penjumlahan
system("CLS");
cout<<endl;
for (i=1; i<=n; i++)
                {
                   for (j=1; j<=n; j++)
                   {
                                  C[i][j]=A[i][j] + B[i][j];
                   }
                  
    }


system("CLS");
                cout<<"Nama : Angga Lisdiyanto"<<endl;
                cout<<"NIM  : 111010534"<<endl;
cout<<"Nilai-Nilai Matrik A, B dan C"<<endl;
cout<<endl;


//output matrik A
gotoxy(1,6);
cout<<"A = ";
for (i=1;i<=n;i++)
{
                for (j=1;j<=n;j++)
    {
       gotoxy(2+4*j,2+2*i);
                                cout<<A[i][j];
                }
}

//output matrik B
                gotoxy(1,18
                                );
                cout<<"B = ";
                for (i=1;i<=n;i++)
                {
                                for (j=1;j<=n;j++)
                                {
                                                gotoxy(2+4*j,14+2*i);
                                                cout<<B[i][j];
                                }
                }


                //output matrik C
 gotoxy(1,31);
                cout<<"C = ";
                for (i=1;i<=n;i++)
                {
                                for (j=1;j<=n;j++)
                                {
                                                gotoxy(3+4*j,27+2*i);
                                                cout<<A[i][j];
                                }
                }

 gotoxy(20,31);
                cout<<" + ";
                for (i=1;i<=n;i++)
                {
                                for (j=1;j<=n;j++)
                                {
                                                gotoxy(26+4*j,27+2*i);
                                                cout<<B[i][j];
                                }
                }


 gotoxy(42,31);
                cout<<" = ";
                for (i=1;i<=n;i++)
                {
                                for (j=1;j<=n;j++)
                                {
                                gotoxy(45+4*j,27+2*i);
                                                cout<<C[i][j];
                                }
                }
                cout<<""<<endl;
                cout<<""<<endl;
                cout<<""<<endl;
    system("PAUSE");
    return EXIT_SUCCESS;
}




0 komentar:

Posting Komentar

 
Back to top!