#include <stdio.h>
void input( int i, int j, int a[ ] [ 100 ] )
{
for ( int x = 0 ; x < i; ++ x )
{
for ( int y = 0 ; y < j; ++ y)
{
}
}
}
void mul_arr( int i, int j, int n, int mul[ ] [ 100 ] , int a[ ] [ 100 ] , int b[ ] [ 100 ] )
{
for ( int x = 0 ; x < i; ++ x)
{
for ( int y = 0 ; y < n; ++ y)
{
mul[ x] [ y] = 0 ;
for ( int z = 0 ; z < j; ++ z)
mul[ x] [ y] += ( a[ x] [ z] * b[ z] [ y] ) ;
}
}
}
void sum_arr( int i, int j, int a[ ] [ 100 ] , int b[ ] [ 100 ] , int sum[ ] [ 100 ] )
{
for ( int x = 0 ; x < i; ++ x)
{
for ( int y = 0 ; y < j; ++ y)
{
sum[ x] [ y] = a[ x] [ y] + b[ x] [ y] ;
}
}
}
void print_sum( int i, int j, int sum[ ] [ 100 ] )
{
printf ( "tong cua 2 ma tran tren:\n " ) ; for ( int x = 0 ; x < i; ++ x)
{
for ( int y = 0 ; y < j; ++ y)
{
}
}
}
void print_mul( int i, int n, int mul[ ] [ 100 ] )
{
printf ( "tich cua 2 ma tran tren:\n " ) ; for ( int x = 0 ; x < i; ++ x)
{
for ( int y = 0 ; y < n; ++ y)
{
}
}
}
int main( )
{
int i, j;
int m, n;
printf ( "nhap vao so hang cua ma tran a: " ) ;
printf ( "nhap vao so cot cua ma tran a:" ) ;
printf ( "nhap vao so hang cua ma tran b:" ) ;
printf ( "nhap vao so cot cua ma tran b:" ) ;
int a[ i] [ j] ;
int b[ m] [ n] ;
int mul[ 100 ] [ 100 ] ;
int sum[ 100 ] [ 100 ] ;
printf ( "nhap cac phan tu cua ma tran a\n " ) ; input( i, j, a) ;
printf ( "nhap cac phan tu cua ma tran b\n " ) ; input( m, n, b) ;
if ( m == j)
{
mul_arr( i, j, n, mul, a, b) ;
print_mul( i, n, mul) ;
}
else
printf ( "2 ma tran tren khong the thuc hien phep nhan!\n " ) ; if ( i == m && j == n)
{
sum_arr( i, j, a, b, sum) ;
print_sum( i, n, sum) ;
}
else
printf ( "2 ma tran tren khong the thuc hien phep cong!\n " ) ;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CnZvaWQgaW5wdXQoaW50IGksIGludCBqLCBpbnQgYVtdWzEwMF0pCnsKICAgIGZvciAoaW50IHggPSAwOyB4IDwgaTsgKyt4ICkKICAgIHsKICAgICAgICBmb3IgKGludCB5ID0gMDsgeSA8IGo7ICsreSkKICAgICAgICB7CiAgICAgICAgICAgIHNjYW5mKCIlZCIsJmFbeF1beV0pOwogICAgICAgIH0KICAgIH0KfQp2b2lkIG11bF9hcnIoaW50IGksIGludCBqLCBpbnQgbiwgaW50IG11bFtdWzEwMF0sIGludCBhW11bMTAwXSwgaW50IGJbXVsxMDBdKQp7CiAgICBmb3IgKGludCB4ID0gMDsgeCA8IGk7ICsreCkKICAgIHsKICAgICAgICBmb3IoaW50IHkgPSAwOyB5IDwgbjsgKyt5KQogICAgICAgIHsKICAgICAgICAgICAgbXVsW3hdW3ldID0gMDsKICAgICAgICAgICAgZm9yIChpbnQgeiA9IDA7IHogPCBqOyArK3opCiAgICAgICAgICAgICAgICBtdWxbeF1beV0gKz0gKGFbeF1bel0gKiBiW3pdW3ldKTsKICAgICAgICB9CiAgICB9Cn0Kdm9pZCBzdW1fYXJyKGludCBpLCBpbnQgaiwgaW50IGFbXVsxMDBdLCBpbnQgYltdWzEwMF0sIGludCBzdW1bXVsxMDBdKQp7CiAgICBmb3IgKGludCB4ID0gMDsgeCA8IGk7ICsreCkKICAgIHsKICAgICAgICBmb3IgKGludCB5ID0gMDsgeSA8IGo7ICsreSkKICAgICAgICB7CiAgICAgICAgICAgIHN1bVt4XVt5XSA9IGFbeF1beV0gKyBiW3hdW3ldOwogICAgICAgIH0KICAgIH0KfQp2b2lkIHByaW50X3N1bShpbnQgaSwgaW50IGosIGludCBzdW1bXVsxMDBdKQp7CiAgICBwcmludGYoInRvbmcgY3VhIDIgbWEgdHJhbiB0cmVuOlxuIik7CiAgICBmb3IgKGludCB4ID0gMDsgeCA8IGk7ICsreCkKICAgIHsKICAgICAgICBmb3IgKGludCB5ID0gMDsgeSA8IGo7ICsreSkKICAgICAgICB7CiAgICAgICAgICAgIHByaW50ZigiJWQgIixzdW1beF1beV0pOwogICAgICAgIH0KICAgICAgICBwcmludGYoIlxuIik7CiAgICB9Cn0Kdm9pZCBwcmludF9tdWwoaW50IGksIGludCBuLCBpbnQgbXVsW11bMTAwXSkKewogICAgcHJpbnRmKCJ0aWNoIGN1YSAyIG1hIHRyYW4gdHJlbjpcbiIpOwogICAgZm9yIChpbnQgeCA9IDA7IHggPCBpOyArK3gpCiAgICB7CiAgICAgICAgZm9yIChpbnQgeSA9IDA7IHkgPCBuOyArK3kpCiAgICAgICAgewogICAgICAgICAgICBwcmludGYoIiVkICIsbXVsW3hdW3ldKTsKICAgICAgICB9CiAgICAgICAgcHJpbnRmKCJcbiIpOwogICAgfQp9CmludCBtYWluKCkKewogICAgaW50IGksajsKICAgIGludCBtLG47CiAgICBwcmludGYoIm5oYXAgdmFvIHNvIGhhbmcgY3VhIG1hIHRyYW4gYTogIik7CiAgICBzY2FuZigiJWQiLCZpKTsKCiAgICBwcmludGYoIm5oYXAgdmFvIHNvIGNvdCBjdWEgbWEgdHJhbiBhOiIpOwogICAgc2NhbmYoIiVkIiwmaik7CgogICAgcHJpbnRmKCJuaGFwIHZhbyBzbyBoYW5nIGN1YSBtYSB0cmFuIGI6Iik7CiAgICBzY2FuZigiJWQiLCZtKTsKCiAgICBwcmludGYoIm5oYXAgdmFvIHNvIGNvdCBjdWEgbWEgdHJhbiBiOiIpOwogICAgc2NhbmYoIiVkIiwmbik7CgogICAgaW50IGFbaV1bal07CiAgICBpbnQgYlttXVtuXTsKICAgIGludCBtdWxbMTAwXVsxMDBdOwogICAgaW50IHN1bVsxMDBdWzEwMF07CgogICAgcHJpbnRmKCJuaGFwIGNhYyBwaGFuIHR1IGN1YSBtYSB0cmFuIGFcbiIpOwogICAgaW5wdXQoaSxqL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