C++ Programming Homework Help
C++ Programming Homework Help
Resource Limits
For any Homework related queries, Call us at : - +1 678 648 4277
You can mail us at : - [email protected] or
reach us at : - https://www.cpphomeworkhelp.com/
3 2
1 1
1 2
-4 0
2 3
1 2 1
3 2 1
Output Format
For any Homework related queries, Call us at : - +1 678 648 4277
You can mail us at : - [email protected] or
reach us at : - https://www.cpphomeworkhelp.com/
We are given
For any Homework related queries, Call us at : - +1 678 648 4277
You can mail us at : - [email protected] or
reach us at : - https://www.cpphomeworkhelp.com/
Solution
/*PROG: matrix
LANG: C
*/
#include <stdio.h>
#include <stdlib.h>
#define MAXN 300
typedef struct Matrix {
size_t R, C;
int index[MAXN]
[MAXN];
} Matrix;
void read_matrix( FILE *fin,
Matrix *matrix ) {
fscanf( fin, "%zu %zu",
&matrix->R, &matrix->C );
For any Homework related queries, Call us at : - +1 678 648 4277
You can mail us at : - [email protected] or
reach us at : - https://www.cpphomeworkhelp.com/
}
for( size_t r = 0; r < matrix->R; ++r ) {
for( size_t c = 0; c < matrix->C; ++c )
{
fscanf( fin, "%d", &matrix->index[r]
[c] );
}
}
}
void print_matrix( FILE *fout, Matrix
*matrix ) {
fprintf( fout, "%zu %zu\n", matrix->R,
matrix->C );
for( size_t r = 0; r < matrix->R; ++r ) {
for( size_t c = 0; c < matrix->C - 1; ++c ) {
fprintf( fout, "%d ", matrix->index[r][c] );
}
fprintf( fout, "%d\n", matrix->index[r]
[matrix->C - 1] );
}
}
For any Homework related queries, Call us at : - +1 678 648 4277
You can mail us at : - [email protected] or
reach us at : - https://www.cpphomeworkhelp.com/
void mult_matrix( Matrix *a,
Matrix *b, Matrix *prod ) {
if( a->C != b->R ) {
printf( "Error: tried to multiply
(%zux%zu)x(%zux%zu)\n", a->R,
a->C, b->R, b->C );
exit( EXIT_FAILURE );
}
size_t inner = a->C;
prod->R = a->R;
prod->C = b->C;
Matrix a, b, c;
read_matrix( fin, &a );
read_matrix( fin, &b );
fclose( fin );
For any Homework related queries, Call us at : - +1 678 648 4277
You can mail us at : - [email protected] or
reach us at : - https://www.cpphomeworkhelp.com/
mult_matrix( &a, &b, &c );
print_matrix( fout, &c );
fclose( fout );
return 0;
}
matrix:
1: OK [0.004 seconds]
2: OK [0.004 seconds]
3: OK [0.004 seconds]
4: OK [0.013 seconds]
5: OK [0.009 seconds]
6: OK [0.006 seconds]
7: OK [0.011 seconds]
8: OK [0.011 seconds]
9: OK [0.012 seconds]
10: OK [0.004 seconds]
For any Homework related queries, Call us at : - +1 678 648 4277
You can mail us at : - [email protected] or
reach us at : - https://www.cpphomeworkhelp.com/