Matrix 为什么我的矩阵在乘以A*B后显示随机数?

Matrix 为什么我的矩阵在乘以A*B后显示随机数?,matrix,Matrix,所以我有这个任务,我必须编写一个程序,对两个矩阵进行乘法。 我的程序向用户询问这两个矩阵的行数和列数。 为了生成矩阵的值,我使用rand函数,然后显示生成的矩阵 #include <iostream> #include<stdio.h> #include<stdlib.h> #include<time.h> using namespace std; int main() { int FA, CA,num; //number is to store

所以我有这个任务,我必须编写一个程序,对两个矩阵进行乘法。 我的程序向用户询问这两个矩阵的行数和列数。 为了生成矩阵的值,我使用rand函数,然后显示生成的矩阵

#include <iostream>
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
using namespace std;

int main()
{
int FA, CA,num; //number is to store the random number
cout<<"Enter the number of rows for MATRIX A "<<endl;
cin>>CA;
cout<<"Enter the number of columns for MATRIX A "<<endl;
cin>>FA;
int A[FA][CA];
int i, j;
for(i=0;i<FA;i++)
{
    for(j=0;j<CA;j++)
    {
        num=rand()%10; //it generates a number ranging from 0 to 10

        A[FA][CA] = num;
        cout<<" "<<A[FA][CA];
    }
    cout<<endl;
}
int FB, CB;
cout<<"Enter the number of rows for MATRIX B "<<endl;
cin>>CB;
cout<<"Enter the number of rows for MATRIX B "<<endl;
cin>>FB;
int B[FB][CB];
for(i=0;i<FB;i++)
{
    for(j=0;j<CB;j++)
    {
        num=rand()%10;
        A[FB][CB] = num;
        cout<<" "<<A[FB][CB];
    }
    cout<<endl;
}
#包括
#包括
#包括
#包括
使用名称空间std;
int main()
{
int FA,CA,num;//number用于存储随机数
库特
if(FB == CA)
    {
        cout<<"Multiplication in progress"<<endl;
        cout<<endl;
        //Creating MATRIX AB
        int AB[FA][CB];
        int k;
        cout<<"MATRIX AB, HAS: "<<  FA << "  ROWS  AND   "<<  CB << " COLUMNS."<<endl;
        //MULTIPLICATION PROCESS
        // START
       for(i=0;i<FA;i++)
        {
            for(j=0;j<CB;j++)
            {
                AB[i][j]=0;
                for(k=0;k<CA;k++)
                {
                    AB[i][j]+=A[i][k]*B[k][j];
                }

            }
            cout<<endl;
        } //finish
        // SHOW AB
        for (int i = 0; i < FA; i++)
            {
                for (int j = 0; j < CB; j++)
                {
                    cout << AB[i][j] << " ";
                }
          // Newline for new row
                cout << endl;
            }




         }
    else
    {
        cout<<"Multiplication can't be done"<<endl;
    }
return 0;
}