#include <stdio.h>

#include <math.h>

#include <string.h>

#include <conio.h>

// The interpreter of arithmetic expressions

// (C) S. Filichev, 2001

main ()

{char T[255];

printf("\n Input Arithmetic expression ");

scanf("%s",T); strcat(T,"=");

int X, BO, I=0; char B; int K=0; char S[30];

double C[20]; char Z[20]; int O[20];

for (X=0; X<strlen(T); X++)

  {B=T[X];

  BO=0;

  if (B=='^') BO=1;

  if (B=='*' || B=='/') BO=2;

  if (B=='+' || B=='-') BO=3;

  if (B=='=' || B==')') BO=4;

  if (B=='(') BO=-4;

  if (BO==0 && B!=' ') {S[K]=B; S[K+1]=0; K++;}

  if (BO!=0)

    {I++; Z[I]=B; O[I]=BO;

    if (K!=0) {C[I]=atof(S); S[0]=0; K=0;}

    while (I>1 && abs(O[I-1])<=O[I])

      {if (Z[I-1]=='^') C[I-1]=pow(C[I-1],C[I]);

      if (Z[I-1]=='*') C[I-1]=C[I-1]*C[I];

      if (Z[I-1]=='/') C[I-1]=C[I-1]/C[I];

      if (Z[I-1]=='+') C[I-1]=C[I-1]+C[I];

      if (Z[I-1]=='-') C[I-1]=C[I-1]-C[I];

      if (Z[I-1]=='(') {C[I-1]=C[I]; I--;}

      else {Z[I-1]=Z[I]; O[I-1]=O[I];}

      I--;

}}}

printf ("%lf",C[1]); getch();

}