Question

Write c program.Program should get two matrices. change the digits of the digits in a different f...

Write c program.Program should get two matrices.

change the digits of the digits in a different function.

INPUT:
It says the input matrices should be martices with order of N, and N should be Even.

OUTPUT:
1st Output matrix should be combination of left half of 1st input matrix and right half of 2nd input matrix

0 0
Add a comment Improve this question Transcribed image text
Answer #1

code :-

#include <stdio.h>

int main(void)
{
   int n;
   scanf("%d",&n);
   if(n%2 ==0 ) // checking whether n is even
   {
   int a[n][n];
   int b[n][n];
   int c[n][n];
   //input in first matrix
   for(int i =0;i<n;i++)
   {
       for(int j=0;j<n;j++)
       {
           scanf("%d",&a[i][j]);
       }
   }
   //input in second matrix
   for(int i =0;i<n;i++)
   {
       for(int j=0;j<n;j++)
       {
           scanf("%d",&b[i][j]);
       }
   }
   //storing the left half elements of first array in output matrix
   for(int i=0;i<n;i++)
   {
       for(int j=0;j<n/2;j++)
       {
           c[i][j]=a[i][j];
       }
   }
   //storing the right half elements of second array in output matrix
   for(int i=0;i<n;i++)
   {
       for(int j=n/2;j<n;j++)
       {
           c[i][j]=b[i][j];
       }
   }
   // printing the output matrix
   for(int i=0;i<n;i++)
   {
       for(int j=0;j<n;j++)
       {
           printf("%d ",c[i][j]);
       }
       printf("\n");
   }
   }
   else
   printf("enter even number");
   return 0;
}

a stdin 4 1 2 3 4 567 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 3Θ 31 32 stdout 12192Θ 5 6 23 24 9 10 2

Add a comment
Know the answer?
Add Answer to:
Write c program.Program should get two matrices. change the digits of the digits in a different f...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • C++ Write a program to calculate the sum of two matrices that are stored inside two-dimensional...

    C++ Write a program to calculate the sum of two matrices that are stored inside two-dimensional arrays. Your program should include three functions: one for getting input data, one for calculating the sum of matrices, and one for printing the result. a) Function inputMatrix: This Function prompts the user to enter the data and stores data inside two-dimensional array. b) Function addMatrices: This function calculatesthe sum result of two matrices. c) Function printMatrix: This function prints the matrix to screen....

  • Write a C++ program to read two matrices with any size. Your program should have at...

    Write a C++ program to read two matrices with any size. Your program should have at least the following functions: Main() Read a matrix Add two matrices Subtract two matrices Multiply two matrices Divide two matrices Display a matrix

  • Write your own matlab code to perform matrix multiplication. Recall that to multiply two matrices, the...

    Write your own matlab code to perform matrix multiplication. Recall that to multiply two matrices, the inner dimensions must be the same. Write this as a function with input arguments the matrices to be multiplied and output argument the resultant matrix, use "assert" statement(s) to check that the input arguments are valid and print an error message if they are not. Test with A=[1,2,3;4,5,6] and B=[7,8;9,10;11,12] showing results for: (a) A*B, (b) B*A, and (c) A*A.

  • Write in C code What to do Write a function with the following signature: float* matrix...

    Write in C code What to do Write a function with the following signature: float* matrix multiplication(float* left, float* right, int rows, int shared, int columns); The first two arguments are two pointers to the beginning of two matrices with the dimensions (rows,shared) and (shared, columns) correspondingly. The remaining arguments specify these dimensions. The return value will return a pointer to the very beginning of the result matrix. That said, you need to provide the space for the result matrix...

  • MUST BE PROCEDURAL CODE. Write a program in C++ that reads two matrices and: 1) adds...

    MUST BE PROCEDURAL CODE. Write a program in C++ that reads two matrices and: 1) adds them (if compatible) and prints their sum, 2) subtracts them (if compatible) and prints their difference, and 3) multiplies them (if compatible) and prints their product. Prompt the user for the names of two matrix input files (see format below) and place the output in a file of the user’s choosing. The format of the input files should contain the number of rows, followed...

  • Please code in MatLab or Octave Output should match Sample Output in the second picture Thank...

    Please code in MatLab or Octave Output should match Sample Output in the second picture Thank You 4. In this problem we will investigate using loops to calculate the product of two matrices. Given an mxn matrix A and an n x p matrix B, the matrix product C = AB is the m xp matrix with Cij = R=1 Qikbky. Write a program which calls a function get matrix.dimensions which should • print a description of the purpose of...

  • MATLAB HELP!!! Recall that if A is an m × n matrix and B is a p × q matrix, then the product C = AB is defined if and on...

    MATLAB HELP!!! Recall that if A is an m × n matrix and B is a p × q matrix, then the product C = AB is defined if and only if n = p, in which case C is an m × q matrix. 5. Recall that if A is an mx n matrix and B is a px q matrix, then the product C-AB is defined if and only if n = p, in which case C is...

  • Please create a C program with the following C code declares variable mtx of matrix type,...

    Please create a C program with the following C code declares variable mtx of matrix type, and dynamically allocates memory for mtx. It will then get keyboard input for the N-by-N matrix. Subsequently, the program de-allocates (free) the memory of the matrix. A. Your task is to write the codes to dynamically allocate and de-allocate the memory for the matrix. B. Subsequently, you have to modify the above code so that now the program will first ask the user to...

  • Write a c++ program: Many mathematical problems require the addition, subtraction, and multiplication of two matrices. Write an ADT Matrix. You may use the following class definition: const int MAX_RO...

    Write a c++ program: Many mathematical problems require the addition, subtraction, and multiplication of two matrices. Write an ADT Matrix. You may use the following class definition: const int MAX_ROWS = 10; const int MAX_COLS = 10; class MatrixType { public: MatrixType(); void MakeEmpty(); void SetSize(int rowsSize, int colSize); void StoreItem(int item, int row, int col); void Add(MatrixType otherOperand, MatrixType& result); void Sub(MatrixType otherOperand, MatrixType& result); void Mult(MatrixType otherOperand, MatrixType& result); void Print(ofstream& outfile); bool AddSubCompatible(MatrixType otherOperand); bool MultCompatible(MatrixType otherOperand);...

  • Write a C program for the following: (i) (ii) (iii) (iv) (v) A function to read...

    Write a C program for the following: (i) (ii) (iii) (iv) (v) A function to read an NxM matrix (from console input). A function to display the NxM matrix on the screen. A function to add these two matrices. A function to subtract these two matrices. A function to multiply these two matrices. The program must also contain a main function that will first declare two 3x3 matrices A and B, allow input of data for A and B (using...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT