Database System Concepts
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
Bartleby Related Questions Icon

Related questions

Question

C programming

Input code in "Enter code here" section

Transcribed Image Text:#include <stdio.h> void matrix_printer( ... ){ printf("MatrixA \t MatrixB\n"); // Enter code here printf("\n"); void matrix_operation( ... ){ printf("\nResult\n"); // Enter code here } int main(){ int matrixA[4][4]; int matrixB[4][4]; char operator; // Enter code here printf("\n"); getchar(); matrix_printer (matrixA, matrixB); printf("Enter operator (+, -): "); do{ scanf ( "%c", &operator); }while(operator != '+' && operator != '-'); matrix_operation(matrixA, matrixB, operator); return 0;
Transcribed Image Text:Print the summed or subtracted result of the 4x4 2D array. An operator (+ or -) MUST be inputted by user. Also, each elements of matrix MUST be inputted by user. Example) >123 4 5 6 7 8 9 10 11 12 13 14 15 16 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 MatrixA MatrixB 123 4 16 15 14 13 12 11 10 9 8765 4 321 5678 9 10 11 12 13 14 15 16 Enter operator(+, -): + Result 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 >123 4 5 67 8 9 10 11 12 13 14 15 16 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 MatrixA MatrixB 123 4 5 678 9 10 11 12 16 15 14 13 12 11 10 9 8765 13 14 15 16 4321 Enter operator(+, -): - Result -15 -13 -11 -9 -7 -5 -3 -1 1357 9 11 13 15
Expert Solution
Check Mark
Step 1

Approach

Function matrix_printer

void matrix_printer(int matrixA[][4], int matrixB[][4]) {
printf("MatrixA \t MatrixB\n");
for (int c = 0; c < 4; c++) {
for (int d = 0 ; d < 4; d++) {

//print matrixA elements
printf("%d ", matrixA[c][d]);
}
printf("\t");
for (int e = 0 ; e < 4; e++) {

//print matrixB elements
printf("%d ", matrixB[c][e]);
}
printf("\n");
}
printf("\n");
}

Function matrix_operation

void matrix_operation(int matrixA[][4], int matrixB[][4], char operator) {
printf("\nResult\n");
int matrixC[4][4];
int c,d;
if (operator == '+') //check if operator is '+'
{
for (c = 0; c < 4; c++) {
for (d = 0 ; d < 4; d++) {
matrixC[c][d] = matrixA[c][d] + matrixB[c][d]; //perform addition
printf("%d ", matrixC[c][d]); //print result
}
printf("\n");
}
}
if (operator == '-') //check if operator is '-'
{
for (c = 0; c < 4; c++) {
for (d = 0 ; d < 4; d++) {
matrixC[c][d] = matrixA[c][d] - matrixB[c][d]; //perform subtraction
printf("%d ", matrixC[c][d]); //print result
}
printf("\n");
}
}
}

bartleby

Step by stepSolved in 2 steps with 2 images

[画像:Blurred answer]
Knowledge Booster
Background pattern image
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Recommended textbooks for you
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education