Giango FinalExam

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

#include <stdio.

h>

int main() {
int a[10][10], b[10][10], c[10][10], sum[10][10], rows, cols, i, j;
float average[10][10];

printf("Enter the number of rows: ");


scanf("%d", &rows);
printf("Enter the number of columns: ");
scanf("%d", &cols);

printf("Enter elements for Matrix A:\n");


for (i = 0; i < rows; i++) {
for (j = 0; j < cols; j++) {
printf("A[%d][%d]: ", i, j);
scanf("%d", &a[i][j]);
}
}

printf("Enter elements for Matrix B:\n");


for (i = 0; i < rows; i++) {
for (j = 0; j < cols; j++) {
printf("B[%d][%d]: ", i, j);
scanf("%d", &b[i][j]);
}
}

printf("Enter elements for Matrix C:\n");


for (i = 0; i < rows; i++) {
for (j = 0; j < cols; j++) {
printf("C[%d][%d]: ", i, j);
scanf("%d", &c[i][j]);
}
}

for (i = 0; i < rows; i++) {


for (j = 0; j < cols; j++) {
sum[i][j] = a[i][j] + b[i][j] + c[i][j];
}
}

for (i = 0; i < rows; i++) {


for (j = 0; j < cols; j++) {
average[i][j] = (float)sum[i][j] / (rows * cols);
}
}

printf("Sum of Matrices A, B, and C:\n");


for (i = 0; i < rows; i++) {
for (j = 0; j < cols; j++) {
printf("%d ", sum[i][j]);
}
printf("\n");
}

printf("Average of the sum matrix:\n");


for (i = 0; i < rows; i++) {
for (j = 0; j < cols; j++) {
printf("%.2f ", average[i][j]);
}
printf("\n");
}

return 0;
}

You might also like