Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

how to solve this

0 votes
asked Jan 1, 2020 by jollymunch
Wrtie a C++ program using functions and arrays create the functionality as follows:.

------------------------------------------------

Press 1 for matrix addition

Press 2 for matrix subtraction

Press 3 for matrix multiplication

Press 4 for reverse main diagonal

Press 5 for largest number in the matrix

Press 6 for smallest number in the matrix

Press 7 for inversing the matrix

Press anything else to exit

-------------------------------------------------------------------

Enter your choice:

------------------------------------------------------------------

Create function add_matrix () for adding matrix

Create function sub_matrix() for matrix subtraction

Create function mul_matrix() for matrix multiplication

Create function rev_diagonal_matrix() for reverse main diagonal

Create function max_matrix() for largest number in the matrix

Create function min_matrix() for smallest number in the matrix

Create function inv_matrix() for inversing the matrix

Your program should be able to continue as long as the user want to continue. Make sure to have appropriate comments in your program.

Do perform relevant checks related to dimensions of matrix.

1 Answer

0 votes
answered Jan 6, 2020 by anonymous
#define SIZE 50
#include<stdio.h>
#include<string.h>
#include <ctype.h>
char s[SIZE]; int top=-1;
char infx[50],prfx[50],ch,elem,pofx[50];
int i=0,k=0;
void push(char elem) {
 s[++top]=elem;
}
char pop() {
 return(s[top--]);
}
int pr(char elem) {
 switch(elem) {
 case '#': return 0;
 case '(': return 1;
 case '+': case '-': return 2;
 case '*': case '/': return 3;
}
}

void main() {
int z;
printf("1.postfix or 2.prefix\n");
scanf("%d",&z);
switch(z) {
 case 1:
 printf("\n\nRead the Infix Expression ? ");
 scanf("%s",infx); push('#');
 while( (ch=infx[i++]) != '\0') {
 if( ch == '(')
 push(ch);
 else if(isalnum(ch))
 pofx[k++]=ch;
 else
 if( ch == ')') {
 while( s[top] != '(')
 pofx[k++]=pop();
 elem=pop();
 }
 else {
 while( pr(s[top])>=pr(ch) )
 pofx[k++]=pop();
 push(ch);
 }
 }
 while( s[top] != '#')     /* Pop from stack till empty */
 pofx[k++]=pop();
 pofx[k]='\0';    /* Make pofx as valid string */
 printf("\n\nGiven Infix Expn: %s  Postfix Expn: %s\n",infx,pofx);
 break;
 case 2:
 printf("\n\nRead the Infix Expression ? ");
 scanf("%s",infx); push('#');
 strrev(infx);
 while( (ch=infx[i++]) != '\0') {
 if( ch == ')')
 push(ch);
 else
 if(isalnum(ch))
 prfx[k++]=ch;
 else if( ch == '(') {
 while( s[top] != ')')
 prfx[k++]=pop();
 elem=pop();
 }
 else{
 while( pr(s[top]) >= pr(ch) )
 prfx[k++]=pop();
 push(ch);
 }
 }
 while( s[top] != '#')
 prfx[k++]=pop();
 prfx[k]='\0';
 strrev(prfx);
 strrev(infx);
 printf("\n\nGiven Infix Expn: %s  Prefix Expn:%s\n",infx,prfx);}
}
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...