Question

In: Computer Science

1. Consider an arithmetic expression of the form a#b=c. Check whether it is possible to replace...

1. Consider an arithmetic expression of the form a#b=c. Check whether it is possible to replace with one of the four signs: +, -, * or / to obtain a correct expression.

Test Sample

a

b

c

Expected Output

1

2

3

5

True

2

8

2

4

True

3

8

3

2

False

4

6

3

3

True

5

5

2

0

False

6

10

2

2

False

Make a MATLAB program

Solutions

Expert Solution

RAW CODE (FOR BOOLEAN OUTPUT)

function val = myfunc(a,b,c)
  if (a+b == c || a-b == c || a/b == c || a*b == c)
      val = true;
  else
      val = false;
  endif
endfunction

y = myfunc(4,2,2)

NOTE:- THIS WILL RETURN OUTPUT IN THE FORM OF 0 (FALSE) AND 1 (TRUE).

SCREENSHOT (CODE AND OUTPUT)

RAW CODE (FOR STRING OUTPUT)

function val = myfunc(a,b,c)
  if (a+b == c || a-b == c || a/b == c || a*b == c)
      val = "True";
  else
      val = "False";
  endif
endfunction

y = myfunc(4,2,2)

NOTE:- THIS WILL RETURN OUTPUT IN THE FORM OF STRING "TRUE" AND "FALSE".

SCREENSHOT (CODE AND OUTPUT)

CODE WITH COMMENTS

##### FOR ANY QUERY, KINDLY GET BACK, THANKYOU. #####


Related Solutions

Question 1: Given the infix arithmetic expression as follows: Exp = Z * ((B + C...
Question 1: Given the infix arithmetic expression as follows: Exp = Z * ((B + C * D) / S + F)             Where the values of the variables are:                         Z = 3, B = 6, C = 2, D = 5, S = 4 , F = 21             Evaluate the expression using a stack. Shows the logical representation of the evaluation process. ..............................................................................
Arithmetic Expression Evaluation Write a program that reads an infix expression (that contains only A, B...
Arithmetic Expression Evaluation Write a program that reads an infix expression (that contains only A, B and/or C as operands) from the user and prints out the value of the expression as an output. Implement the following methods: o String infixToPostfix(String expr) Converts the given infix expression expr and returns the corresponding postfix notation of expr. o Integer evaluatePostfixExpr(String expr) Evaluates and returns the value of the given postfix expression expr. Sample Input/Output #1 Enter your arithmetic expression: A+B-C*A Enter...
write a program that evaluates the following arithmetic expression: ((A+B)/C)*((D-A)+E). Assign test values to the variables...
write a program that evaluates the following arithmetic expression: ((A+B)/C)*((D-A)+E). Assign test values to the variables and display the resulting value.
Write a C++ function that takes in an arithmetic expression in prefix notation and converts it...
Write a C++ function that takes in an arithmetic expression in prefix notation and converts it into a binary tree, such that each operation is stored in a node whose left subtree stores the left operand, and whose right subtree stores the right operand.
: In this assignment you will write a C++ program that evaluates an arithmetic expression (represented...
: In this assignment you will write a C++ program that evaluates an arithmetic expression (represented with an infix notation), then outputs this expression in prefix form and also outputs the result of the calculation. The program will first convert the input infix expression to a prefix expression (using the Stack ADT) and then calculate the result (again, using the Stack ADT). The details are provided in the following sections.
Consider the class C of all intervals of the form (a, b), a, b ∈ R,...
Consider the class C of all intervals of the form (a, b), a, b ∈ R, a < b and ∅. Show that C is closed under finite intersections but not under complementations or unions. Hint: to show closure of finite intersections, it is enough to prove closure for intersections of 2 sets.
) Consider a game where player 1’s possible three strategies are a, b and c and...
) Consider a game where player 1’s possible three strategies are a, b and c and player 2’s possible strategies are A, B and C. The players choose their strategies simultaneously. The payoff matrix of the game is as follows:                                           Player 2 A B C    a 8,5 9,7 10,8 player 1 b 6,1 10,3 7,9 c 5,4 8,6 6,4 (5 pts) Is there a dominated strategy for player 1? For player 2? Justify your answer. (5 pts) Is...
If A, B, and C events are independent, check if B and A \ C events...
If A, B, and C events are independent, check if B and A \ C events are independent or not.
For the following infix expression, build the corresponding expression tree. 1.1 a*b 1.2 a+b*c 1.3 a+b*c/d-e...
For the following infix expression, build the corresponding expression tree. 1.1 a*b 1.2 a+b*c 1.3 a+b*c/d-e Perform pre-order and post-order traversal of the above binary expression trees. What relationship exists among these scans and prefix and postfix notation for the expression?
Bezout’s Theorem and the Fundamental Theorem of Arithmetic 1. Let a, b, c ∈ Z. Prove...
Bezout’s Theorem and the Fundamental Theorem of Arithmetic 1. Let a, b, c ∈ Z. Prove that c = ma + nb for some m, n ∈ Z if and only if gcd(a, b)|c. 2. Prove that if c|ab and gcd(a, c) = 1, then c|b. 3. Prove that for all a, b ∈ Z not both zero, gcd(a, b) = 1 if and only if a and b have no prime factors in common.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT