E Materi Materi by Adri Priadana


Source Code Penjumlahan, Pengurangan, Perkalian Matrik Bahasa C

by adri in Algoritma dan Pemrograman - 2014-12-26 17:20:17

Operasi pada matematika seperti penjumlahan, pengurangan, dan perkalian dapat juga diimplementasikan kedalam pemrograman menggunakan bahasa C.

#include <stdio.h>
#include <conio.h>

void main(){

int j,i,k,a[2][2],b[2][2],c[2][2];
a[0][0]=3;
a[0][1]=2;
a[1][0]=1;
a[1][1]=4;

b[0][0]=4;
b[0][1]=1;
b[1][0]=3;
b[1][1]=2;

printf("
Matrik a 
");
for (i=0; i<2; i++){
  for(j=0;j<2;j++){
    printf(" %d",a[i][j]);
  }
  printf("
");
}

printf("
Matrik b 
");

for (i=0; i<2; i++){
  for(j=0;j<2;j++){
    printf(" %d",b[i][j]);
  }
  printf("
");
}

printf("
Hasil a+b 
");
for (i=0; i<2; i++){
  for(j=0;j<2;j++){
    c[i][j]=a[i][j]+b[i][j];
    printf(" %d",c[i][j]);
  }
  printf("
");
}

printf("
Hasil a-b 
");
for (i=0; i<2; i++){
  for(j=0;j<2;j++){
    c[i][j]=a[i][j]-b[i][j];
    printf(" %d",c[i][j]);
  }
  printf("
");
}

printf("
Hasil a*b 
");
for (i=0; i<2; i++){
  for(j=0;j<2;j++){
    c[i][j]=0;
    for(k=0;k<2;k++){
      c[i][j]+=a[i][k]*b[k][j];
    }
    printf(" %d",c[i][j]);
  }
  printf("
");
}

getch();
}


You may also like...


Comments

Leave A Comment

Make sure you enter the (*) required information where indicated. HTML code is not allowed.