Advertisement
Guest User

Donia

a guest
Nov 17th, 2018
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.38 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<conio.h>
  3. int main(int argc, char** argv) {
  4.     int n, p;
  5.     int matrix[100][100];
  6.     int result[100][100];
  7.     printf("Enter the dimension: ");
  8.     scanf("%d", &n);
  9.     printf("Enter the multiplication power: ");
  10.     scanf("%d", &p);
  11.    
  12.    
  13.    
  14.     printf("Enter the elements of second matrix\n");
  15.     for ( int c = 0 ; c < n ; c++ ) {
  16.         for ( int d = 0 ; d < n ; d++ ) {
  17.             printf("[%d][%d] = ", c+1, d+1);
  18.             scanf("%d", &matrix[c][d]);
  19.         }
  20.     }
  21.    
  22.     int sum = 0;
  23.     for (int i = 0; i < p; i++)
  24.     {
  25.         for ( int c = 0 ; c < n ; c++ )
  26.         {
  27.             for (int d = 0 ; d < n ; d++ )
  28.             {
  29.                 for (int k = 0 ; k < n ; k++ )
  30.                 {
  31.                     sum += matrix[c][k]*matrix[k][d];
  32.                 }
  33.                 result[c][d] = sum;
  34.                 sum = 0;
  35.             }
  36.          }
  37.        
  38.         for ( int c = 0 ; c < n ; c++ ) {
  39.             for ( int d = 0 ; d < n ; d++ ) {
  40.                 matrix[c][d] = result[c][d];
  41.                 result[c][d] = 0;
  42.             }
  43.         }
  44.     }
  45.    
  46.     printf("Product of entered matrices:-\n");
  47.  
  48.     for (int c = 0 ; c < n ; c++ )
  49.     {
  50.         for (int d = 0 ; d < n ; d++ )
  51.         {
  52.             printf("%d   ", matrix[c][d]);            
  53.         }
  54.         printf("\n");
  55.     }
  56.    
  57.     getch();
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement