Friday, October 23, 2015

Algoritma Pengurangan Matriks Ordo 3x2

Anggota Kelompok : 

  • Glen Hizkia Oge Mangundap ( D1041141059 )
  • Jefri Hasiholan Simanjuntak ( D1041141027 )
  • Iqbal tri Hartanto ( D1041141055 )

Soal :

Buatlah algoritma untuk untuk menghitung matriks di bawah ini :




x ← 3
for i ← 1 to 3 do
            begin
            for j ← 1 to 2 do
                        begin 
                        A[i,j] ← x
                        Print A[i][j]
                        x ← x + 3
                        end
            end

x ← 1
for i ← 1 to 3 do
            begin
            for j ← 1 to 2 do
                        begin 
                        B[i,j] ← x
                        Print B[i][j]
                        x ← x + 2
                        end
            end

for i ← 1 to 3 do
            begin 
            for j ← 1 to 2 do
                        begin
                        C[i,j] ← A[i,j] - B[i,j]
                        Print C[i][j]
                        end
            end




Program C++
#include <conio>
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
void main()
{
    int A[3][2];
    int B[3][2];
    int C[3][2];
    int i,j;
    int x=3;
    int y=1;

    cout << " __________________" << endl ;
    printf("\n");
    cout << "     Matriks A" << endl ;
    printf("\n");
    cout << " __________________" << endl ;
    printf("\n");
    for(i=0;i<3;i++){
                        for(j=0;j<2;j++){
                        A[i][j]=x;
               printf("%7d", A[i][j]);
                                    x=x+3;
         }
                                       printf("\n");
    }

    cout << " __________________" << endl ;
    printf("\n");
    cout << "     Matriks B" << endl ;
    printf("\n");
    cout << " __________________" << endl ;
    printf("\n");
    for(i=0;i<3;i++){
                        for(j=0;j<2;j++){
                        B[i][j]=y;
               printf("%7d", B[i][j]);
                                    y=y+2;
         }
                                       printf("\n");
    }

    cout << " __________________" << endl ;
    printf("\n");
    cout << "       A - B" << endl ;
    printf("\n");
    cout << " __________________" << endl ;
    printf("\n");
    for(i=0;i<3;i++){
                        for(j=0;j<2;j++){
                        C[i][j]=A[i][j]-B[i][j];
                        printf("%7d", C[i][j]);

         }
                                       printf("\n");
    }


getch();
}

No comments:

Post a Comment