Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Design And Relational Theory Normal Forms And All That Jazz

Authors: Chris Date

1st Edition

1449328016, 978-1449328016

More Books

Students also viewed these Databases questions

Question

=+What is the extent of the use of each type of IE?

Answered: 1 week ago

Question

Provide examples of KPIs in Human Capital Management.

Answered: 1 week ago

Question

What are OLAP Cubes?

Answered: 1 week ago