Untitled
unknown
plain_text
5 years ago
1.3 kB
8
Indexable
#include <stdio.h>
#include <stdlib.h>
float * matrix3D(char letter);
void matrixPrint(int r, int c, float *matrix);
int main(void)
{
int stu_id = 70357003;
float *Mat_A, *Mat_B;
printf("Please enter two 3-by-3 matrices below.\n");
printf("Please enter for the first matrix called 'Mat_A'.\n");
Mat_A = matrix3D('A');
printf("Please enter for the second matrix called 'Mat_B'.\n");
Mat_B = matrix3D('B');
printf("Mat_A: \n");
matrixPrint(3, 3, Mat_A);
puts("");
printf("Mat_B: \n");
matrixPrint(3, 3, Mat_B);
printf("\n\nStudent ID: %d\n\n", stu_id);
return 0;
}
float * matrix3D(char letter){
static float matrix[3][3];
float element;
printf("Please enter the elements row-by-row\n");
for(int i = 0; i < 3; i++){
for(int j = 0; j < 3; j++){
printf("Mat_%c [%d][%d]: ", letter, i, j);
scanf("%f", &element);
}
}
return matrix;
}
void matrixPrint(int r, int c, float *matrix){
printf("Matrix in 2-D format:\n");
for(int i = 0; i < r; i++){
for(int j = 0; j < c; j++){
printf("%f ", *(matrix + i*3 + j));
if(j == c - 1){
printf("\n");
}
}
}
}Editor is loading...