Business

Wednesday, 1 July 2015

Pemrograman (Metode Pembuatan Matriks)

#include<conio.h>
#include<stdio.h>
#include<iomanip.h>
#include<iostream.h>
#include<math.h>
main()
{
int A[10][10];
int B[10][10];
int C[10][10];
int temp;
int a1,b1,a,b,c;
char P;
cout<<endl;

cout<<endl;
cout<<endl;
cout<<"====================================================";cout<<endl;
cout<<"                 TUGAS ANALISIS NUMERIK             ";cout<<endl;
cout<<"                    OPERASI MATRIKS                 ";cout<<endl;
cout<<"=====================================================";cout<<endl;
cout<<endl;

textcolor(9);cprintf("   TAMPILAN MATRIKS A DAN MATRIK B   ");cout<<endl;
cout<<endl;
cout<<" Masukkan jumlah kolom matriks=";cin>>a1;
cout<<" Masukkan jumlah baris matriks=";cin>>b1;
cout<<endl;
cout<<"\n Input Elemen Martriks A : \n";
for( a=1;a<=a1;a++)
    {
for( b=1;b<=b1;b++)
    {
cout<<" masukkan elemen ke ("<<a<<","<<b<<")= ";
cin>>A[a][b];
}
}
textcolor(13);cprintf("\n Martriks A \n");cout<<endl;
for( a=1;a<=a1;a++)
    {
for( b=1;b<=b1;b++)
    {
cout<<A[a][b];
cout<<"     ";
}
cout<<endl;
}
cout<<endl;
cout<<" Masukkan jumlah kolom matriks=";cin>>a1;
cout<<" Masukkan jumlah baris matriks=";cin>>b1;
cout<<endl;
cout<<"\n Input Elemen Martriks B : \n";
for( a=1;a<=a1;a++)
    {
for( b=1;b<=b1;b++)
    {
cout<<" masukkan elemen ke ("<<a<<","<<b<<")= ";
cin>>B[a][b];
}
}
textcolor(12);cprintf("\n Martriks B \n");cout<<endl;
for( a=1;a<=a1;a++)
    {
for( b=1;b<=b1;b++)
    {
cout<<A[a][b];
cout<<"     ";
}
cout<<endl;
}
cout<<endl;
textcolor(15);cprintf(" Pilihan Operasi Matriks : ");cout<<endl;
textcolor(15);cprintf(" 1. (+) Penjumlahan ");cout<<endl;
textcolor(15);cprintf(" 2. (-) Pengurangan ");cout<<endl;
textcolor(15);cprintf(" 3. (T) Transpose ");cout<<endl;
textcolor(15);cprintf(" 4. (*) Perkalian ");cout<<endl;
textcolor(15);cprintf(" Ingin operasi matriks dengan simbol yang mana?  ");cin>>P;
if(P=='+')
{
cout<<endl;
textcolor(9);cprintf("   Penjumlahan Matriks (A + B) : ");cout<<endl;
textcolor(9);cprintf("\n Matriks C \n");cout<<endl;
for ( a=1;a<=a1;a++)
    {
for ( b=1;b<=b1;b++)
   {
   C[a][b]=(A[a][b])+(B[a][b]);
    printf(" %4d ",C[a][b]);
}
cout<<endl;
}
}
else if(P=='-')
{
cout<<endl;
textcolor(11);cprintf("   Pengurangan Matriks (A - B) : ");cout<<endl;
textcolor(11);cprintf("\n   Matriks C \n");cout<<endl;
for ( a=1;a<=a1;a++)
    {
for ( b=1;b<=b1;b++)
   {
    C[a][b]=(A[a][b])-(B[a][b]);
    printf(" %4d ",C[a][b]);
}
cout<<endl;
}
}
else if (P=='T')
{
cout<<endl;
textcolor(12);cprintf("      TRANSPOSE Martriks A : ");cout<<endl;
for( a=1;a<=b1;a++)
    {
for( b=1;b<=a1;b++)
    {
    cout<<A[b][a];
    cout<<"     ";
}
cout<<endl;
}
cout<<endl;
textcolor(12);cprintf("     TRANSPOSE Martriks B : ");cout<<endl;
for( a=1;a<=b1;a++)
    {
for( b=1;b<=a1;b++)
    {
    cout<<B[b][a];
    cout<<"     ";
}
cout<<endl;
}
}
else if(P=='*')
{
cout<<endl;
textcolor(13);cprintf("   Perkalian Matriks (A x B) : ");cout<<endl;
cout<<endl;
cout<<"\Matriks C \n";
for ( a=1;a<=a1;a++)
    {
for ( b=1;b<=b1;b++)
    {
C[a][b]=0;
for ( c=1;c<=b1;c++)
    {
temp=A[a][c]*B[c][b];
C[a][b]=C[a][b]+temp;
}
}
}
cout<<endl;
for ( a=1;a<=a1;a++)
    {
for ( b=1;b<=b1;b++)
    {
    cout<<C[a][b];
    cout<<"  ";
}
cout<<endl;
}
}
getche();
}

0 komentar:

Post a Comment