Matice násobenie v c

Príklady kódu

0
0

matice násobenie v c

#include <stdio.h>

int main()
{   int a_rows,a_cols,b_rows,b_cols,i,j,k,sum=0;

    printf("Enter the rows and columns for first matrix (row)(col)  :\n");
    scanf("%d %d",&a_rows,&a_cols);

    printf("Enter the rows and columns for second matrix (row)(col) :\n");
    scanf("%d %d",&b_rows,&b_cols);
    int a[a_rows][a_cols], b[b_rows][b_cols],matrix[10][10];

    if(a_cols != b_rows){
        printf("Sorry! We can't multiply the matrix because the column number of matrix 1 and the row number of matrix 2 aren't same !!\n");
        
    }else{
        printf("Enter elements for first matrix  :\n");
       for(i = 0; i < a_rows; i++){
           for(j = 0; j< a_cols; j++){
               scanf("%d",&a[i][j]);
           }
       }

    printf("Enter elements for second matrix  :\n");

       for(i = 0; i < b_rows; i++){
           for(j = 0; j < b_cols; j++){
               scanf("%d",&b[i][j]);
           }
       }

       printf("multiplying matrix....\n");
       //multiplying matrix
       for(i=0; i < a_rows; i++){
           for(j = 0; j < b_cols; j++){
               for(k = 0; k < a_cols; k++){
                   sum+=a[i][k] * b[k][j];
               }
               matrix[i][j] = sum;
               sum=0;
               
           }
           printf("\n");
       }

       printf("first matrix  :\n");
       for(i = 0; i < a_rows; i++){
           for(j = 0; j< a_cols; j++){
               printf("%d ",a[i][j]);
           }
           printf("\n");
       }


        printf("\n\n");

       printf("second matrix  :\n");
       for(i = 0; i < b_rows; i++){
           for(j = 0; j< b_cols; j++){
               printf("%d ",b[i][j]);
           }
           printf("\n");
       }


       printf("Multiplied matrix  :\n");
       for(i = 0; i < a_rows; i++){
           for(j = 0; j< b_cols; j++){
               printf("%d ",matrix[i][j]);
           }
           printf("\n");
       }
    }

     

    return 0;
}
0
0

násobenie matice v c

enter the number of row=3
enter the number of column=3
enter the first matrix element=
1 1 1
8 8 8
3 3 3
enter the second matrix element=
1 1 1
2 2 2
3 3 3
multiply of the matrix=
6 6 6
12 12 12
18 18 18

Podobné stránky

Podobné stránky s príkladmi

V iných jazykoch

Táto stránka je v iných jazykoch

Русский
..................................................................................................................
English
..................................................................................................................
Italiano
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
한국어
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
ไทย
..................................................................................................................
中文
..................................................................................................................
Español
..................................................................................................................
Балгарскі
..................................................................................................................
Íslensk
..................................................................................................................