#include <stdio.h>
#include <stdlib.h> /* for atof() */
#include<ctype.h>
#define NUMBER '0'
int getop(char []);
void push(double);
double pop(void);
double value[100];
int sp = 0;
char buf[100];
int bufp = 0;

int getch(void);
void ungetch(int);
main()
{
    int type;
    double op2;
    char s[100];
    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 '\n':
            printf("%.8g\n", pop());
            break;
            default:
            break;
        }
    }
}
void push(double f)
{
    if(sp < 100)
        value[sp++]=f;
    else
        printf("error\n");
}

double pop(void)
{
    if(sp>0)
        return value[--sp];
    else
    {
        printf("error\n");
        return 0.0;
    }
}

int getop(char s[])
{
    int i,c;

    while((s[0] = c = getch()) == ' ' || c =='\t')
        ;
    s[1] = '\0';
    
    i = 0;
    if(!isdigit(c) && c!='.' && c!='-')
        return c;

    if(c=='-')
        if(isdigit(c=getch()) || c == '.')
            s[++i]=c;
        else
        {
            if(c!=EOF)
                ungetch(c);
            return '-';
        }
    
    if(isdigit(c))
        while(isdigit(s[++i] =c =getch()))
            ;

    if(c=='.')
        while(isdigit(s[++i] = c=getch()))
            ;
    
    s[i] = '\0';
    if(c!=EOF)
        ungetch(c);
    return NUMBER;
}


int getch(void)
{
    return (bufp > 0) ? buf[--bufp] : getchar();
}

void ungetch(int c)
{
    if(bufp >= 100)
        printf("error");
    else
        buf[bufp++] = c;
}
{
    int item;
    if(top == -1) // Checking Array is empty or not.
    {
    	return -1; 
    }
    item = stack[top];
    top -= 1; //	top = top - 1
    return item;
}

