Saturday, December 3, 2011

program perkalian matrik



PROGRAM PERKALIAN MENNGUKAN C++

#include<stdio.h>
void main()
{
       int n_i=2,n_j=2,n_k=1;

       int A[2][2],B[2][1],C[2][1];
       int i,j,k;
       //____________________________________
       printf("masukkan Nilai Matriks P\n");
       for (i=0;i<n_i;i++)
       {
                       for (j=0;j<n_j;j++)
                       {
                                       printf("Baris ke-%i Kolom ke-%i : ",i+1,j+1); scanf("%i",&A[i][j]);
                       }
       }
       //_______________________________________
       printf("\nmasukkan Nilai Matriks Q\n");
       for (j=0;j<n_j;j++)
       {
                       for (k=0;k<n_k;k++)
                       {
                                       printf("Baris ke-%i Kolom ke-%i : ",j+1,k+1); scanf("%i",&B[j][k]);
                       }
       }
       //_________________________________________
       printf("\nPerhitungan sedang dilakukan...");
       for (i=0;i<n_i;i++)
       {
                       for (k=0;k<n_k;k++)
                       {
                                       C[i][k]=0;
                                       for (j=0;j<n_j;j++)
                                       {
                                                       C[i][k]=C[i][k]+A[i][j]*B[j][k];
                                       }
                       }
       }

       printf("\n");
       printf("\nhasil kali matrik P & matrik Q atau matrik R:\n");
       for (i=0;i<n_i;i++)
       {
                       for (k=0;k<n_k;k++)
                       {
                                       printf("|%i|",C[i][k]);
                       }
                       printf("\n");
       }
}

No comments:

Post a Comment