answersLogoWhite

0


Best Answer

A simple calculator works strictly left to right:

  1. get a number as the result of the last operation (if there is no number make it zero)
  2. make the result of the last operation the current number
  3. get the next operator
  4. if there is no next operator or it is equals (=) go to step 8
  5. get the next number
  6. do the operator on the current number and the next number
  7. go to step 2
  8. print the result of the last operator
  9. stop
You need to:
  • decide what to do if two operators are found together without an intervening number;
  • decide how to detect a unary minus (ie when a '-' is found, is it a binary "number - number", or a unary "negate following number"
  • how to handle the numbers - work with integers, fixed point or floating point, etc.
  • decode the operator and do the relevant operation on the stored numbers.

-----------------------------------

A reverse polish calculator is actually much easier to code (than a simple calculator), but allows the user to specify precedence of operations (like a scientific calculator) or to use it as a simple calculator (left-to-right):

  1. Initialise the stack
  2. get an object
  3. if no more objects go to step 12
  4. if the object is a number go to step 9
  5. if the are not at least 2 numbers on the stack error
  6. do the operation on under and top (eg under ÷ top)
  7. remove the top two numbers and push the result on the stack
  8. repeat from step 2
  9. if stack full error
  10. push the number on the stack
  11. repeat form step 2
  12. If stack empty push 0 onto the stack
  13. print top number on stack
  14. clear the stack
  15. stop

A simple calculator would evaluate: "1 + 3 x 2" as "(1 + 3) x 2" = 4 x 2 = 8

The reverse polish calculator would have the same calculation entered as "1 3 + 2 x"

User Avatar

Wiki User

6y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

6y ago

The answer depends on algorithm for carrying out which operation!

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What is the algorithm for simple calculator?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

What is the rules that a calculator follows in performing a series of steps is called?

algorithm


How do you draw an algorithm to find the simple interest?

The answer depends on what information you do have.


What is 15 dollars and 75 cents times 6?

15.75 dollars * 6 = 94.50 dollars. So simple with a calculator!15.75 dollars * 6 = 94.50 dollars. So simple with a calculator!15.75 dollars * 6 = 94.50 dollars. So simple with a calculator!15.75 dollars * 6 = 94.50 dollars. So simple with a calculator!


Where is there a gold value calculator online?

In order to find a gold calculator, it requires a very simple search. Google has a very simple and easy calculator to use and so does GoldCalculator.


What exactly is a simple mortgage calculator?

A simple mortgage calculator is a device which will calculate mortgage figures. A mortgage calculator may also be an accountant who derives the figures through accounting.


Code to develop a calculator in adobe flex?

here is the code for simple calculator in flex,[Bindable] private var _txt:Object;[Bindable] private var _choos:String;private function satu():void{txtLayar.text = txtLayar.text + '1';}private function dot():void{txtLayar.text = txtLayar.text + '.';}private function dua():void{txtLayar.text = txtLayar.text + '2';}private function tiga():void{txtLayar.text = txtLayar.text + '3';}private function empat():void{txtLayar.text = txtLayar.text + '4';}private function lima():void{txtLayar.text = txtLayar.text + '5';}private function enam():void{txtLayar.text = txtLayar.text + '6';}private function tujuh():void{txtLayar.text = txtLayar.text + '7';}private function lapan():void{txtLayar.text = txtLayar.text + '8';}private function sembilan():void{txtLayar.text = txtLayar.text + '9';}private function noll():void{txtLayar.text = txtLayar.text + '0';}private function clear():void{txtLayar.text = '';}private function sum():void{_txt = txtLayar.text;_choos = '1';txtLayar.text = '';}private function sub():void{_txt = txtLayar.text;_choos = '2';txtLayar.text = '';}private function mul():void{_txt = txtLayar.text;_choos = '3';txtLayar.text = '';}private function div():void{_txt = txtLayar.text;_choos = '4';txtLayar.text = '';}private function hasil():void{var txt2:Number = Number(txtLayar.text);var txt3:Number = Number(_txt);var has:Number;if(_choos=='1'){has = txt3 + txt2;}else if(_choos == '2'){has = txt3 - txt2;}else if(_choos == '3'){has = txt3 * txt2;}else if(_choos == '4'){has = txt3 / txt2;}txtLayar.text = has.toString();}]]>


Where can one find a free simple mortgage calculator?

There are a variety of places that one could find a free simple mortgage calculator. A free simple mortgage calculator can be found at HSH to compare rates of mortgage and to find the calculation of mortgage costs.


How do you work out 5 divided by 18?

0.2778


Where can you find a simple conversion calculator?

7


How can you convert a simple algorithm to recursive algorithm?

Linear search(a,item) n=length(a) for i=1 to n do if(a[i]==item) then return i end for return -1


C program algorithm for simple interest using while loop?

Not used


What are the disadvantage of bresenham's circle drawing algorithm?

The main advantage of Bresenham's algorithm is speed. The disadvantage of such a simple algorithm is that it is meant for basic line drawing. The "advanced" topic of antialiasing isn't part of Bresenham's algorithm, so to draw smooth lines, you'd want to look into a different algorithm.