矩阵mul

    技术2022-05-11  2

     #include"stdio.h"

    void main(){ int A[5][4] = {1,5,7,3,                3,6,3,9,                1,2,8,7,                0,3,1,9,                3,2,5,4}; int B[4][6] = {3,9,1,4,1,4,                5,6,7,9,0,3,       3,2,7,2,5,6,       9,7,4,7,8,0}; int C[5][6]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; int i ; //循环变量 int ii; //循环变量  相乘的条件ii不能大于4 int j;  //循环变量  for(i = 0 ; i < 5; i++) {  for(j = 0 ; j < 6; j++)  {   for(ii = 0 ; ii < 4; ii++)    C[i][j]=C[i][j]+A[i][ii]*B[ii][j];//计算  }

     }

       printf("矩阵A是:/n");  //输出矩阵A   for(i = 0 ; i < 5 ; i++)   {    for( j = 0 ; j < 4 ;j++)     printf("%d/t",A[i][j]);    printf("/n");   }

       printf("========================/n");      printf("矩阵B是:/n");//输出矩阵B   for(i = 0 ; i < 4 ; i++)   {    for( j = 0 ; j < 6 ;j++)     printf("%d/t",B[i][j]);    printf("/n");   }

       printf("========================/n");      printf("A*B结果C是:/n");//输出矩阵C   for(i = 0 ; i < 5; i++ ) {    for(j = 0; j < 6; j++)   printf("%d/t",C[i][j]);  printf("/n"); }}


    最新回复(0)