#include<stdio.h> #include<stdlib.h> #include<string.h> main() { char str[100],str1[100],str2[100],sym; int i,j; double a,b; while(1) { gets(str),str1[0]=str[0],i=1,j=1; while(str[i]) if(str[i]!='+'&&str[i]!='-'&&str[i]!='*'&&str[i]!='/') str1[j++]=str[i++]; else {str1[j]='\0';break;} a=strtod(str1,NULL); while(str[i]) { sym=str[i++],str2[0]=str[i++],i=i,j=1; while(str[i]) if(str[i]!='+'&&str[i]!='-'&&str[i]!='*'&&str[i]!='/') str2[j++]=str[i++]; else {str2[j]='\0';break;} b=strtod(str2,NULL); switch(sym) { case '+':a+=b;break; case '-':a-=b;break; case '*':a*=b;break; case '/':a/=b;break; } } printf("%lf\n",a); } getch(); } |