Question: You are required to write a C program to carry out a strict-left-to-right evaluation of an arithmetic expression consisting of integer constants and the operators

You are required to write a C program to carry out a strict-left-to-right evaluation of an arithmetic expression consisting of integer constants and the operators +, -, * and /. Here, the operator / denotes integer division; that is, the remainder is discarded. In a strict-left-to-right evaluation, there is no notion of precedence. For example, the value of the expression 6+4*3 when evaluated in a strict-left-to-right fashion is 30. (Under usual precedence rules, where multiplication has higher precedence than addition, the value of the above expression would be 18.) Similarly, the value of the expression 6+4*3/7-9 when evaluated in a strict-left-to-right fashion is = -5.

Here is some additional information about the input.

Each input expression is terminated by the newline (' ') character.

There may be zero or more spaces between successive non-blank characters of an expression.

You may assume that the given expression is valid; that is, it satisfies all of the following

conditions.

The expression consists only of integer constants, the operators +, -, * and / and spaces.

In particular, the expression won't contain parentheses.

Each integer constant in the expression consists of only one decimal digit.

The expression begins with an integer constant, without any preceding sign.

In the expression, integer constants and operators alternate.

Note that an expression consisting of a single digit integer constant, without any operators, is a valid expression. The outline of your C program is as follows.

1) Prompt the user for an expression.

2) Read the expression character by character and carry out a strict-left-to-right evaluation of the

expression.

3) Print the value of the result obtained in Step 2 and stop.

Thus, each time your program is executed, it should handle just one expression. No error checks are needed.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!