Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<conio.h>
- int main(int argc, char** argv) {
- int n, p;
- int matrix[100][100];
- int result[100][100];
- printf("Enter the dimension: ");
- scanf("%d", &n);
- printf("Enter the multiplication power: ");
- scanf("%d", &p);
- printf("Enter the elements of second matrix\n");
- for ( int c = 0 ; c < n ; c++ ) {
- for ( int d = 0 ; d < n ; d++ ) {
- printf("[%d][%d] = ", c+1, d+1);
- scanf("%d", &matrix[c][d]);
- }
- }
- int sum = 0;
- for (int i = 0; i < p; i++)
- {
- for ( int c = 0 ; c < n ; c++ )
- {
- for (int d = 0 ; d < n ; d++ )
- {
- for (int k = 0 ; k < n ; k++ )
- {
- sum += matrix[c][k]*matrix[k][d];
- }
- result[c][d] = sum;
- sum = 0;
- }
- }
- for ( int c = 0 ; c < n ; c++ ) {
- for ( int d = 0 ; d < n ; d++ ) {
- matrix[c][d] = result[c][d];
- result[c][d] = 0;
- }
- }
- }
- printf("Product of entered matrices:-\n");
- for (int c = 0 ; c < n ; c++ )
- {
- for (int d = 0 ; d < n ; d++ )
- {
- printf("%d ", matrix[c][d]);
- }
- printf("\n");
- }
- getch();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement