Need to write a program that evaluates a postfix expression which is input by the user and then displays the answer.

조회 수: 2 (최근 30일)
For example, if the user inputs 493*+ then the program should evaluate this postfix expression and display the answer. The user input can vary and the total number of characters may also vary. So, this should also be taken into consideration while writing the program. Thanks!

답변 (1개)

Bjorn Gustavsson
Bjorn Gustavsson 2017년 2월 2일
If you want us to do your assignments you might have a better chance if you explicitly ask us to. What have you done so far?
Small tip: if current character (token rather!) is a number put it on a stack, if it is an operator take contents of stack and perform operation on those.
HTH
  댓글 수: 2
naveen selvan
naveen selvan 2017년 2월 7일
Thanks for the reply. But, I am unable to convert a postfix expression into individual characters. For example, if the user inputs 123*+ as the postfix expression, I am currently storing it as a string. But, then I am unable to read the string by one character at a time. So, I am stuck right there. If I could read the individual characters, I could solve the rest as the logic is quite simple. Pls help!
Walter Roberson
Walter Roberson 2017년 2월 7일
current_position = 5
current_character = input_string(current_position)
if current_character == '0'
... do something appropriate
elseif current_character == '2'
.... do something appropriate
elseif current_character == '{'
... do something appropriate
elseif current_character == '⁞'
... do something appropriate
end

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 MATLAB Compiler에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by