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. ..............................................................................
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.
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.
1- Consider the following resource allocation graph and check whether it contains deadlock or not? Justify...
1- Consider the following resource allocation graph and check whether it contains deadlock or not? Justify your answer in detail. 2- Consider the following page reference string: 4, 6, 7, 8, 6, 7, 8, 4, 6, 4, 4, 7, 5, 8 Assuming demand paging with three frames, how many page faults would occur for the following replacement algorithms? illustrate your work. FIFO replacement. LRU replacement. 3- What is swapping? explain the terms "swap in" and "swap out" with a neat...
1. In each of A-C, below, indicate whether: a) the statement is possible under the laws...
1. In each of A-C, below, indicate whether: a) the statement is possible under the laws of thermodynamics; b) the statement violates the First Law; c) the statement violates the Second Law. In the case of a Second Law violation, circle the name of the scientist whose version of the second law is most simply and obviously broken. In each case there is a best name, but feel free to explain your choice. (Adapted from Bill Reinhardt.) A. A novel...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT