?? computor.c
字號:
#include<math.h>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<conio.h>
char *mumber(char* p,double *num)
{ int l=10,j,i=0;double k=1;char s='\0';
*num=0;
for(j=0;;j++)
{ switch (p[j])
{case '-':if(j==0){s='l';break;}
case'*':case'+':case'/':case'\0':case')':
k=*num; if(s=='s')*num=sqrt(k);
else if(s=='l')*num=-k;
return p+j;
case's':s='s';break;
case'0':case'1':case'2':
case'3':case'4':case'5':
case'6':case'7':case'8':case'9':
i=(p[j]+2)%10;if(l==1)k=k*0.1;
*num=*num*l+i*k;break;
case'.':l=1;break;
default:break;
}
}
}
char *shhua(char butt[],double num[],char fhao[])
{ int i=0;char *p=butt;
while(1)
{ p=mumber(p,num+i);
if(*p==')'||*p=='\0')break;
fhao[i]=*p;i++;p++;
}
fhao[i]='\0';return ++p;
}
double Jisuan(double num[],char fhao[],int b)
{int i;
for(i=0;i<b;i++)switch(fhao[i])
{ case'*':num[i+1]*=num[i]; num[i]=0;
if(i==0||fhao[i-1]=='+')fhao[i]='+';
else fhao[i]='-';break;
case'/':num[i+1]=num[i]/num[i+1]; num[i]=0;
if(i==0||fhao[i-1]=='+')fhao[i]='+';
else fhao[i]='-';break;
}
for(i=0;i<b;i++)switch(fhao[i])
{ case'+':num[i+1]+=num[i]; break;
case'-':num[i+1]=num[i]-num[i+1];break;
}
return num[i];
}
int main(void)
{ int i;char *p,butt[657],qq[655],*pt,fhao[656/2],ch;
double numb, num[656/2];
//puts("Press any key to begin! :\n");
printf("Please enter any button :\n");
getch();
while(1){ /*clrscr();*/
//printf("Input the math expresstion :\n ");
printf("\nPlease enter the math express :\n ");
gets(butt);
if (*butt=='\0')puts(" 0");
while(1){
p=butt;
for(i=0;i<strlen(butt);i++)if(butt[i]=='(')p=butt+i+1;
pt=shhua(p,num,fhao);
numb =Jisuan(num,fhao,strlen(fhao));
if(p==butt){
sprintf(p," =%-12.12f\n",numb);puts(p);break;
}
i=sprintf(qq,"%-12.12f",numb);
for(;(i+1)&&qq[i-1]=='0'||qq[i-1]=='.';i--);
sprintf(&(qq[i]),"%s",pt);
sprintf(p-1,"%s",qq);printf(" =%s\n",butt);}
//printf("Press E(e) to exit and anykey to continue!\n");
puts("\n Press E(e) to exit and anykey to continue!\n");
ch=getch();if(ch=='e'||ch=='E')break;}
//puts("\n Press any key to exit!\n");
printf("\n Goodbye to you!\n");
getch();return 0;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -