Penjumlahan matriks 3×4

/* Program penjumlahan matriks dua dimensi */
#include <stdio.h>
#include <conio.h>

void main()
{ int A[3][4], B[3][4], X[3][4], Y[3][4], C[3][4], i, j;
clrscr();

/******* Masukkan matriks A *******/
for(i=0;i<3;i++)
{ for(j=0;j<4;j++)
{  printf(“input data matrik A[%i][%i] : “,i+1,j+1);
fflush(stdin);scanf(“%i”,&A[i][j]);
}
}

/******** Masukkan matriks B ********/
for(i=0;i<3;i++)
{  for(j=0;j<4;j++)
{  printf(“input data matrik B[%i][%i] : “,i+1,j+1);
fflush(stdin);scanf(“%i”,&B[i][j]);
}
}

/******** Proses penjumlahan matriks A dan B ********/
for(i=0;i<3;i++)
{  for(j=0;j<4;j++)
{  X[i][j]=A[i][j]+B[i][j];
}
}

/******** Cetak isi matriks A ********/
printf(“\n matrik A\n”);
for(i=0;i<3;i++)
{  for(j=0;j<4;j++)
printf(“%6i”,A[i][j]);
printf(“\n”);
}
printf(“\n”);

/******** Cetak isi matriks B *******/
printf(“\n matrik B\n”);
for(i=0;i<3;i++)
{  for(j=0;j<4;j++)
printf(“%6i”,B[i][j]);printf(“\n”);
}
printf(“\n”);

/******** Cetak hasil penjumlahan matriks A dan B *******/
printf(“\n matrik penjumlahan A+B\n”);
for(i=0;i<3;i++)
{  for(j=0;j<4;j++)
printf(“%6i”,X[i][j]);printf(“\n”);
}
printf(“\n\n”);

getch();
}

2 Tanggapan

  1. kalau matrix 4*4 array 2D gimana?

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s

%d blogger menyukai ini: