Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <math.h>
- #define MAXOP 100
- #define NUMBER '0'
- int getop(char[]);
- void push(double);
- double pop(void);
- /* RPN reverse polish notation calculator*/
- //pseudo code, not done yet
- main(){
- int type;
- double op2;
- char s[MAXOP];
- while((type=getop(s))!=EOF){
- switch(type){
- case NUMBER:
- push(atof(s));
- break;
- case '+':
- push(pop()+pop());
- break;
- case '*':
- push(pop()*pop());
- break;
- case '-':
- op2=pop();
- push(pop()-op2);
- break;
- case '/':
- op2-pop();
- if(op2!=0.0)
- push(pop()/op2);
- else
- printf("greska, deljenje nulom\n");
- break;
- case '\n':
- printf("|t%.8g\n", pop());
- break();
- default:
- printf("greska, nepoznata operacija %s\n", s);
- break;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement