Hello all... I want the multiplication of the same matrix but in third, forth, fifth... degree. I have made the C++ program and this is the code:
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
using namespace std;
#define WIDTH 3
#define HEIGHT 3
void main(){
int a[HEIGHT][WIDTH];
int b[HEIGHT][WIDTH];
int n;
for (int i = 0; i <= HEIGHT - 1; i++) {
for (int j = 0; j <= WIDTH - 1; j++) {
//cout << "\n Intput a[" << i << "][" << j << "]: ";
//cin >> a[i][j];
a[i][j]= rand()%100 + 1;
}
cout << "\n";
}
cout << "\n Before Multiplication: \n";
for (int i = 0; i <= HEIGHT - 1; i++) {
for (int j = 0; j <= WIDTH - 1; j++) {
cout << a[i][j] << " ";
}
cout << "\n";
}
cout << "\n\n After multiplication: \n\n";
int sum=0;
for (int i = 0; i <= HEIGHT - 1; i++) {
for (int j = 0; j <= WIDTH - 1; j++) {
sum=0;
for (int k = 0; k <= WIDTH - 1; k++) {
//System.out.print("a["+i+"]["+k+"] * a["+k+"]["+j+"] \n");
sum += a[i][k]*a[k][j];
}
b[i][j]=sum;
}
}
for (int i = 0; i <= HEIGHT - 1; i++) {
for (int j = 0; j <= WIDTH - 1; j++) {
cout << b[i][j] << " ";
}
cout << "\n";
}
}