C programming Input code in "Enter code here" section

C++ for Engineers and Scientists
4th Edition
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Bronson, Gary J.
Chapter8: I/o Streams And Data Files
Section: Chapter Questions
Problem 8PP: (Data processing) A bank’s customer records are to be stored in a file and read into a set of arrays...
icon
Related questions
Question

C programming

Input code in "Enter code here" section

#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:#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;
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
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
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");
       }
     }
 }

steps

Step by step

Solved in 2 steps with 2 images

Blurred answer
Knowledge Booster
Function Arguments
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.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
New Perspectives on HTML5, CSS3, and JavaScript
New Perspectives on HTML5, CSS3, and JavaScript
Computer Science
ISBN:
9781305503922
Author:
Patrick M. Carey
Publisher:
Cengage Learning