Question

Write a C program for the following: (i) (ii) (iii) (iv) (v) A function to read an NxM matrix (from console input). A functio

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

#include<stdlib.h> main() int A[3] [3]; array declarations int B[3] [3]; printf (Enter matrix A elements :\n\n); input (A):void input (int num[3] [3] { int i, j; for (i = 0; i < 3; ++i) :,i+l); printf(Enter the $d row elemnts for(j = 0; j < 3; ++// subtracting matrix void Subtract (int A[3] [3], int B[3] [3]) { int i, j; printf (Subtract matrix :\n\n); for (i = 0; i- 0 X C:\Users\N V KDocuments\fcs.exe Enter matrix A elements : Enter the 1 row elemnts :2 3 4 Enter the 2 row elemnts :3 4

source code:

#include<stdio.h>
#include<stdlib.h>
main()
{
int A[3][3]; //array declarations
int B[3][3];
printf("Enter matrix A elements :\n\n");
input(A); //calling input functions
printf("Enter matrix B elements :\n\n");
input(B);

int n;
int x=1;
while(x)
{
printf("1.Add matrix\n");
printf("2.Subtract matrices\n");
printf("3.multiply matrices\n");
printf("4.exit\n");
printf("Please enter your choice 1-4\n");
scanf("%d",&n);

switch(n) //switch case
{
case 1: Add(A,B);
break;
case 2: Subtract(A,B);
break;
case 3: Multiply(A,B);
break;
case 4: exit(0); //if you enter 4 program terminates...
break;}}}
  


void input(int num[3][3])
{ int i,j;


for ( i = 0; i < 3; ++i)
{
printf("Enter the %d row elemnts :",i+1);
for ( j = 0; j < 3; ++j)
scanf("%d", &num[i][j]);
}
}


void Add(int A[3][3],int B[3][3]) //adding method
{ int i,j;

printf("Adding matrix :\n\n");
for ( i = 0; i < 3; ++i) //outer loop no.of rows
{ for ( j = 0; j < 3; ++j) //inner loop
printf("%d\t",A[i][j]+B[i][j]); //adding elements of matrix A and B
printf("\n");
}

}

void Subtract(int A[3][3],int B[3][3]) //subtracting matrix
{ int i,j;
printf("Subtract matrix :\n\n");

for ( i = 0; i < 3; ++i) //outer loop no.of rows
{ for ( j = 0; j < 3; ++j) //inner loop
printf("%d\t",A[i][j]-B[i][j]); //subtracting elements of matrix A and B
printf("\n");
}

}

void Multiply(int A[3][3], int B[3][3]) //method multiplicatoin
{
printf("matrix after multiplication\n\n");
int i, j, k;
for (i = 0; i < 3; i++)
{
for (j = 0; j < 3; j++) //this is for matrix multiplication
{
int value = 0;
for (k = 0; k < 3; k++)
value += A[i][k]*B[k][j];
printf("%d\t",value);
}
printf("\n");
}
}

Add a comment
Know the answer?
Add Answer to:
Write a C program for the following: (i) (ii) (iii) (iv) (v) A function to read...
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
  • 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

  • Please make a JAVA program for the following using switch structures Write a program that simulates...

    Please make a JAVA program for the following using switch structures Write a program that simulates a simple Calculator program. The program will display menu choices to the user to Add, Subtract, Multiply and Divide. The program will prompt the user to make a selection from the choices and get their choice into the program. The program will use a nested if….else (selection control structure) to determine the user’s menu choice. Prompt the user to enter two numbers, perform the...

  • CE – Return and Overload in C++ You are going to create a rudimentary calculator. The...

    CE – Return and Overload in C++ You are going to create a rudimentary calculator. The program should call a function to display a menu of three options: 1 – Integer Math 2 – Double Math 3 – Exit Program The program must test that the user enters in a valid menu option. If they do not, the program must display an error message and allow the user to reenter the selection. Once valid, the function must return the option...

  • extra credit 1 Write a program that will display the following menu and prompt the user...

    extra credit 1 Write a program that will display the following menu and prompt the user for a selection: A) Add two numbers B) Subtract two numbers C) Multiply two numbers D) Divide two numbers X) Exit program The program should: display a hello message before presenting the menu accept both lower-case and upper-case selections for each of the menu choices display an error message if an invalid selection was entered (e.g. user enters E) prompt user for two numbers...

  • 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);...

  • 06) Write a C program to perform matrix operations based of threads. The program accepts from...

    06) Write a C program to perform matrix operations based of threads. The program accepts from the user a positive integer N. A menu is given to the user: 1. generate matrices: generates three NxN matrices A, B, C with random integer numbers between 0 and 9 2. add: matrix D- A+B+C 3. subtract: matrix D A-B-C 4. display matrices: A, B, C, D 5. display count of result values more than 8. 6. exit: terminate the program When the...

  • This is a quick little assignment I have to do, but I missed alot of class...

    This is a quick little assignment I have to do, but I missed alot of class due to the Hurricane and no one here knows what theyre doing. please help! this is Java with intelli-J Overview In this project students will build a four-function one-run calculator on the command line. The program will first prompt the user for two numbers, then display a menu with five operations. It will allow the user to select an option by reading input using...

  • Creating a Calculator Program

    Design a calculator program that will add, subtract, multiply, or divide two numbers input by a user.Your program should contain the following:-The main menu of your program is to continue to prompt the user for an arithmetic choice until the user enters a sentinel value to quit the calculatorprogram.-When the user chooses an arithmetic operation (i.e. addition) the operation is to continue to be performed (i.e. prompting the user for each number, displayingthe result, prompting the user to add two...

  • Develop a flowchart and then write a menu-driven C++ program that uses several FUNCTIONS to solve...

    Develop a flowchart and then write a menu-driven C++ program that uses several FUNCTIONS to solve the following program. -Use Microsoft Visual C++ .NET 2010 Professional compiler using default compiler settings. -Use Microsoft Visio 2013 for developing your flowchart. -Adherence to the ANSI C++  required -Do not use <stdio.h> and <conio.h>. -Do not use any #define in your program. -No goto statements allowed. Upon execution of the program, the program displays a menu as shown below and the user is prompted to make a selection from the menu....

  • ‘C’ programming language question Write a MENU DRIVEN program to A) Count the number of vowels...

    ‘C’ programming language question Write a MENU DRIVEN program to A) Count the number of vowels in the string B) Count the number of consonants in the string C) Convert the string to uppercase D) Convert the string to lowercase E) Display the current string X) Exit the program The program should start with a user prompt to enter a string, and let them type it in. Then the menu would be displayed. User may enter option in small case...

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