Contoh Program Operasi pertambahan 2 matrik.
#include <stdio.h>
#include <conio.h>
#define maks 3
main()
{
int mat1[maks][maks], mat2[maks][maks], mathasil[maks][maks];
int b,k;
printf(“Pengisian Matrik 1 : \n”);
for (b=0;b<maks;b++)
{
for (k=0;k<maks;k++)
{
printf(“Matrik [%d,%d] : “,b,k);
scanf(“%d”,&mat1[b][k]);
}
}
printf(“Pengisian Matrik 2 : \n”);
for (b=0;b<maks;b++)
{
for (k=0;k<maks;k++)
{
printf(“Matrik [%d,%d] : “,b,k);
scanf(“%d”,&mat2[b][k]);
}
}
// awal operasi pertambahan matrik
for (b=0;b<maks;b++)
for (k=0;k<maks;k++)
mathasil[b][k]=mat1[b][k]+mat2[b][k];
// akhir operasi perhitungan
printf(“Matrik 1 :\n”)
for (b=0;b<maks;b++)
{
for (k=0;k<maks;k++)
{
printf(“%6d”,mat1[b][k]);
}
printf(“\n”);
}
printf(“Matrik 2 :\n”)
for (b=0;b<maks;b++)
{
for (k=0;k<maks;k++)
{
printf(“%6d”,mat2[b][k]);
}
printf(“\n”);
}
printf(“Matrik Hasil :\n”)
for (b=0;b<maks;b++)
{
for (k=0;k<maks;k++)
{
printf(“%6d”,mathasil[b][k]);
}
printf(“\n”);
}
getch();
return 0;
}
Posting Komentar