利用你现有的c语言知识 设计开发一个c语言简易计算器代码,可进行加、减、乘、除、求余运算。

您还未登陆,请登录后操作!
谁能帮我设计一个多功能计算器(C语言程序设计)
(加、减、乘、除)运算功能。
依次输入第一个运算数、运算符(+,-,*,/),第二个运算数,然后输出结果。
结果可以作为下一个运算的第一运算数。按&C&清屏,按&X&退出。
例如:输入:2+5
输出:7
2)实现单运算符表达式计算的功能。
输入的操作数可以包含整数或浮点数。如果遇到错误的表达式,应输出错误提示信息。
输入表达式如下:
例如:输入:2+5
输出:7
#include &stdlib.h&
#include &math.h&
#include &graphics.h&
#include &stdio.h&
#include &process.h&
#define EXCAPE 27
#define ENTER 13
int press,i,x,y,x1,y1,ch_z=0;
int dian=0;
char ch='0'; /*input + - * / */
char emp[80],sum[80],*e,*s;
double yuan=0.;
void init(void);
void clear_z(char *u);
double strtoflt(char *p);
int getkey();
int gd=DETECT,
initgraph(&gd, &gm, "");
x = (getmaxx() / 2) - 120;
#include &stdlib.h&
#include &math.h&
#include &graphics.h&
#include &stdio.h&
#include &process.h&
#define EXCAPE 27
#define ENTER 13
int press,i,x,y,x1,y1,ch_z=0;
int dian=0;
char ch='0'; /*input + - * / */
char emp[80],sum[80],*e,*s;
double yuan=0.;
void init(void);
void clear_z(char *u);
double strtoflt(char *p);
int getkey();
int gd=DETECT,
initgraph(&gd, &gm, "");
x = (getmaxx() / 2) - 120;
y = (getmaxy() / 2) - 150;
x1 = (getmaxx() / 2) + 120;
y1 = (getmaxy() / 2) + 150;
press = getkey();
switch(press){
case EXCAPE:
bar (x + 10, y + 80 + 10, x + 60 - 10, y + 80 + 60 - 10);
delay(8000);
if (ch!='0'){
switch(ch){
case '/':
if (strtoflt(emp)==0.0){
ch='0';
emp[0]='\0';
sum[0]='\0';
outtextxy(x+30,y+40,"error!!!!!");
yuan = strtoflt(sum) / strtoflt(emp);
sprintf(sum,"%0.10f",yuan);
clear_z(sum);
outtextxy(x+30,y+40,sum);
case '*':
yuan = strtoflt(sum) * strtoflt(emp);
sprintf(sum,"%0.10f",yuan);
clear_z(sum);
outtextxy(x+30,y+40,sum);
case '+':
yuan = strtoflt(sum) + strtoflt(emp);
sprintf(sum,"%0.10f",yuan);
clear_z(sum);
outtextxy(x+30,y+40,sum);
case '-':
if (strtoflt(sum)&=strtoflt(emp)){
yuan = strtoflt(sum) - strtoflt(emp);
sprintf(sum,"%0.10f",yuan);
yuan=strtoflt(emp)-strtoflt(sum);
sprintf(sum,"-%0.10f",yuan);
clear_z(sum);
outtextxy(x+30,y+40,sum);
emp[0]='\0';
if (ch_z==0){
outtextxy(x+30,y+40,emp);
stpcpy(sum,emp);
outtextxy(x+30,y+40,sum);
ch='/';
emp[0]='\0';
bar (x + 60 + 10, y + 80 + 10, x + 60 * 2 - 10, y + 80 + 60 - 10);
delay(8000);
if (ch!='0'){
switch(ch){
case '/':
yuan = strtoflt(sum) / strtoflt(emp);
sprintf(sum,"%0.10f",yuan);
clear_z(sum);
outtextxy(x+30,y+40,sum);
emp[0]='\0';
case '*':
yuan = strtoflt(sum) * strtoflt(emp);
sprintf(sum,"%0.10f",yuan);
clear_z(sum);
outtextxy(x+30,y+40,sum);
emp[0]='\0';
case '+':
yuan = strtoflt(sum) + strtoflt(emp);
sprintf(sum,"%0.10f",yuan);
clear_z(sum);
outtextxy(x+30,y+40,sum);
emp[0]='\0';
case '-':
if (strtoflt(sum)&=strtoflt(emp)){
yuan = strtoflt(sum) - strtoflt(emp);
sprintf(sum,"%0.10f",yuan);
yuan=strtoflt(emp)-strtoflt(sum);
sprintf(sum,"-%0.10f",yuan);
clear_z(sum);
outtextxy(x+30,y+40,sum);
emp[0]='\0';
if (ch_z==0){
outtextxy(x+30,y+40,emp);
stpcpy(sum,emp);
outtextxy(x+30,y+40,sum);
ch='*';
bar (x + 60 * 2 + 10, y + 80 + 10, x + 60 * 3 - 10, y + 80 + 60 - 10);
delay(8000);
if (ch!='0'){
switch(ch){
case '/':
yuan = strtoflt(sum) / strtoflt(emp);
sprintf(sum,"%0.10f",yuan);
clear_z(sum);
outtextxy(x+30,y+40,sum);
emp[0]='\0';
case '*':
yuan = strtoflt(sum) * strtoflt(emp);
sprintf(sum,"%0.10f",yuan);
clear_z(sum);
outtextxy(x+30,y+40,sum);
emp[0]='\0';
case '+':
yuan = strtoflt(sum) + strtoflt(emp);
sprintf(sum,"%0.10f",yuan);
clear_z(sum);
outtextxy(x+30,y+40,sum);
emp[0]='\0';
case '-':
if (strtoflt(sum)&=strtoflt(emp)){
yuan = strtoflt(sum) - strtoflt(emp);
sprintf(sum,"%0.10f",yuan);
yuan=strtoflt(emp)-strtoflt(sum);
sprintf(sum,"-%0.10f",yuan);
clear_z(sum);
outtextxy(x+30,y+40,sum);
emp[0]='\0';
if (ch_z==0){
outtextxy(x+30,y+40,emp);
stpcpy(sum,emp);
outtextxy(x+30,y+40,sum);
ch='-';
bar (x + 60 * 3 + 10, y + 80 + 10, x + 60 * 4 - 10, y + 80 + 60 - 10);
delay(8000);
if (ch!='0'){
switch(ch){
case '/':
yuan = strtoflt(sum) / strtoflt(emp);
sprintf(sum,"%0.10f",yuan);
clear_z(sum);
outtextxy(x+30,y+40,sum);
emp[0]='\0';
case '*':
yuan = strtoflt(sum) * strtoflt(emp);
sprintf(sum,"%0.10f",yuan);
clear_z(sum);
outtextxy(x+30,y+40,sum);
emp[0]='\0';
case '+':
yuan = strtoflt(sum) + strtoflt(emp);
sprintf(sum,"%0.10f",yuan);
clear_z(sum);
outtextxy(x+30,y+40,sum);
emp[0]='\0';
case '-':
if (strtoflt(sum)&=strtoflt(emp)){
yuan = strtoflt(sum) - strtoflt(emp);
sprintf(sum,"%0.10f",yuan);
yuan=strtoflt(emp)-strtoflt(sum);
sprintf(sum,"-%0.10f",yuan);
clear_z(sum);
outtextxy(x+30,y+40,sum);
emp[0]='\0';
if (ch_z==0){
outtextxy(x+30,y+40,emp);
stpcpy(sum,emp);
outtextxy(x+30,y+40,sum);
ch='+';
bar (x + 10, y + 80 + 53 + 10, x + 60 - 10, y + 80 + 53 * 2 - 4);
delay(8000);
for (i=0;i&=79;i++){
if (emp[i]=='\0')
if (ch_z==0){
*e='1';e++;*e='\0';
outtextxy(x+30,y+40,emp);
outtextxy(x+30,y+40,sum);
bar (x + 60 + 10, y + 80 + 53 + 10, x + 60 * 2 - 10, y + 80 + 53 * 2 - 4);
delay(8000);
for (i=0;i&=79;i++){
if (emp[i]=='\0')
if (ch_z==0){
*e='2';e++;*e='\0';
outtextxy(x+30,y+40,emp);
outtextxy(x+30,y+40,sum);
bar (x + 60 * 2 + 10, y + 80 + 53 + 10, x + 60 * 3 - 10, y + 80 + 53 * 2 - 4);
delay(8000);
for (i=0;i&=79;i++){
if (emp[i]=='\0')
if (ch_z==0){
*e='3';e++;*e='\0';
outtextxy(x+30,y+40,emp);
outtextxy(x+30,y+40,sum);
case ENTER:
bar (x + 60 * 3 + 10, y + 80 + 53 + 10, x + 60 * 4 - 10, y + 80 + 53 * 2 - 4);
delay(8000);
if (ch!='0'){
switch(ch){
case '/':
yuan = strtoflt(sum) / strtoflt(emp);
sprintf(sum,"%0.10f",yuan);
clear_z(sum);
outtextxy(x+30,y+40,sum);
emp[0]='\0';
case '*':
yuan = strtoflt(sum) * strtoflt(emp);
sprintf(sum,"%0.10f",yuan);
clear_z(sum);
outtextxy(x+30,y+40,sum);
emp[0]='\0';
case '+':
yuan = strtoflt(sum) + strtoflt(emp);
sprintf(sum,"%0.10f",yuan);
clear_z(sum);
outtextxy(x+30,y+40,sum);
emp[0]='\0';
case '-':
if (strtoflt(sum)&=strtoflt(emp)){
yuan = strtoflt(sum) - strtoflt(emp);
sprintf(sum,"%0.10f",yuan);
yuan=strtoflt(emp)-strtoflt(sum);
sprintf(sum,"-%0.10f",yuan);
clear_z(sum);
outtextxy(x+30,y+40,sum);
emp[0]='\0';
if (ch_z==0){
outtextxy(x+30,y+40,emp);
stpcpy(sum,emp);
outtextxy(x+30,y+40,sum);
ch='0';
bar (x + 10, y + 80 + 53 * 2 + 10, x + 60 - 10, y + 80 + 53 * 3 - 4);
delay(8000);
if (ch_z==0){
*e='4';e++;*e='\0';
outtextxy(x+30,y+40,emp);
outtextxy(x+30,y+40,sum);
bar (x + 60 + 10, y + 80 + 53 * 2 + 10, x + 60 * 2 - 10, y + 80 + 53 * 3 - 4);
delay(8000);
if (ch_z==0){
*e='5';e++;*e='\0';
outtextxy(x+30,y+40,emp);
outtextxy(x+30,y+40,sum);
bar (x + 60 * 2 +10, y + 80 + 53 * 2 + 10, x + 60 * 3 - 10, y + 80 + 53 * 3 - 4);
delay(8000);
if (ch_z==0){
*e='6';e++;*e='\0';
outtextxy(x+30,y+40,emp);
outtextxy(x+30,y+40,sum);
bar (x + 60 * 3 + 10, y + 80 + 53 * 2 + 10, x + 60 * 4 - 10, y + 80 + 53 * 3 - 4);
delay(8000);
if (dian==0){
if (ch_z==0){
*e='.';e++;*e='\0';
outtextxy(x+30,y+40,emp);
outtextxy(x+30,y+40,sum);
if (ch_z==0)
outtextxy(x+30,y+40,emp);
outtextxy(x+30,y+40,sum);
bar (x + 10, y + 80 + 53 * 3 + 10, x + 60 - 10, y + 80 + 53 * 4 - 4);
delay(8000);
if (ch_z==0){
*e='7';e++;*e='\0';
outtextxy(x+30,y+40,emp);
outtextxy(x+30,y+40,sum);
bar (x + 60 + 10, y + 80 + 53 * 3 + 10, x + 60 * 2 -10, y + 80 + 53 * 4 - 4);
delay(8000);
if (ch_z==0){
*e='8';e++;*e='\0';
outtextxy(x+30,y+40,emp);
outtextxy(x+30,y+40,sum);
bar (x + 60 * 2 + 10, y + 80 + 53 * 3 + 10, x + 60 * 3 - 10, y + 80 + 53 * 4 - 4);
delay(8000);
if (ch_z==0){
*e='9';e++;*e='\0';
outtextxy(x+30,y+40,emp);
outtextxy(x+30,y+40,sum);
bar (x + 60 * 3 + 10, y + 80 + 53 * 3 + 10, x + 60 * 4 - 10, y + 80 + 53 * 4 - 4);
delay(8000);
if (ch_z==0){
*e='0';e++;*e='\0';
outtextxy(x+30,y+40,emp);
outtextxy(x+30,y+40,sum);
emp[0]='\0';
sum[0]='\0';
ch='0';
delay(8000);
for(i=0;i&=79;i++){
if (emp[i]=='\0')
if (i!=79&&i!=0){
emp[i]='\0';
e=&emp[i];
outtextxy(x+30,y+40,emp);
/*---------------------------------------------------------------------*/
void init(void){
int x, y, x1, y1, i,
x = (getmaxx() / 2) - 120;
y = (getmaxy() / 2) - 150;
x1 = (getmaxx() / 2) + 120;
y1 = (getmaxy() / 2) + 150;
cleardevice();
setbkcolor(3);
setfillstyle(1, 15);
setcolor(15);
settextstyle(1,0,1);
rectangle (x, y, x1, y1);
rectangle (x - 7, y - 7, x1 + 7, y1 + 7);
rectangle (x + 10, y + 10, x1 - 10, y + 80 - 10);
line (x, y + 80, x1, y + 80);
y = y + 80;
for (j = 1; j &= 4; j++){
x = (getmaxx() / 2) - 120;
for (i = 1; i &= 4; i++){
/* bar (x + 10, y + 10, x + 60 - 10, y + 60 - 10);*/
rectangle(x + 10, y + 10, x + 60 - 10, y + 60 - 10);
if (j == 1){
if (i == 1)
outtextxy(x + 20, y + 20, "/");
if (i == 2)
outtextxy(x + 25, y + 20, "*");
if (i == 3)
outtextxy(x + 27, y + 20, "-");
if (i == 4)
outtextxy(x + 25, y + 20, "+");
if (j == 2){
if (i == 1)
outtextxy(x + 25, y + 20, "1");
if (i == 2)
outtextxy(x + 25, y + 20, "2");
if (i == 3)
outtextxy(x + 25, y + 20, "3");
if (i == 4)
outtextxy(x + 25, y + 20, "=");
if (j == 3){
if (i == 1)
outtextxy(x + 25, y + 20, "4");
if (i == 2)
outtextxy(x + 25, y + 20, "5");
if (i == 3)
outtextxy(x + 25, y + 20, "6");
if (i == 4)
outtextxy(x + 25, y + 20, ".");
if (j == 4){
if (i == 1)
outtextxy(x + 25, y + 20, "7");
if (i == 2)
outtextxy(x + 25, y + 20, "8");
if (i == 3)
outtextxy(x + 25, y + 20, "9");
if (i == 4)
outtextxy(x + 25, y + 20, "0");
x = x + 60;
y = y + 53;
/*---------------------------------------------------------------------*/
int getkey(){
while(bioskey(1)==0);
press = bioskey(0);
press = press&0xff? press&0xff: press&&8;
return(press);
double strtoflt(char *p)
double rtl=0.;
double pnt=0.;
double t = 10;
int ispoint = 0;
while (*p!='\0'||*p!='.'){
if(*p&'0'||*p&'9')
rtl+=*p-'0';
if (*p=='.'){
ispoint=1;
while(ispoint&&*p!='\0'){
pnt+=(double)(*p-'0')/t;
return (rtl);
/*-----------------------------------------------------------------------*/
void clear_z(char u[]){
for(i=strlen(u)-1;i&=0;i--){
if (u[i]!='0')
if (u[i]=='.'){
u[i]='\0';
u[i]='\0';
++,.NET,Java,Delphi,VB/VB.NET的朋友们欢迎加入 ,一起讨论,一起提高.
小问题#include...
您的举报已经提交成功,我们将尽快处理,谢谢!
求最小值时,看n中含有奇数个还是偶数个奇数,
奇数个奇数时,无论如何加减组合,最小值是最小正奇数1,(n=4k+1,4k+2形式)
偶数个奇数时,总能通过加...
大家还关注设计一个简易计算器,要求:能够进行任意多个数的加减乘除四则运算_c语言吧_百度贴吧
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&签到排名:今日本吧第个签到,本吧因你更精彩,明天继续来努力!
本吧签到人数:0成为超级会员,使用一键签到本月漏签0次!成为超级会员,赠送8张补签卡连续签到:天&&累计签到:天超级会员单次开通12个月以上,赠送连续签到卡3张
关注:342,919贴子:
设计一个简易计算器,要求:能够进行任意多个数的加减乘除四则运算收藏
#include &stdio.h&#include &stdlib.h&int main(void){int num1;int num2;int resule=0;setbuf(stdout,NULL);printf(&请输入两个要进行运算的数字,以逗号隔开:\n&);scanf(&%d,%d&,&num1,&num2);sign=getchar();/*scanf从缓冲区中读取数,此句读取两个数之后的回车符。否则回车符被下面的scanf语句读去赋给sign */printf(&请输入运符号(+、-、*、/):\n&);scanf(&%c&,&sign);if(sign!='+' && sign!='-' && sign!='*' && sign!='/'){printf(&您输入的运算符有问题!\n&);system(&PAUSE&);return 0;}switch(sign){case '+':resule=num1+num2;case '-':resule=num1-num2;case '*':resule=num1*num2;case '/':if(0==num2){printf(&当您使用除法时,您输入的第二个数不能用0!\n&);system(&PAUSE&);return 0;}elseresule=num1/num2;}printf(&%d&,resule);system(&PAUSE&);return 0;}
登录百度帐号推荐应用
为兴趣而生,贴吧更懂你。或C语言作业,编写一个简单的计算器,实现加减乘除运算,谢谢大家_百度知道
C语言作业,编写一个简单的计算器,实现加减乘除运算,谢谢大家
提问者采纳
#include&stdio.h&#include&math.h&#include&stdlib.h&int&cls(){ system(&cls&);&&&&&&&&&&&&&&&&&return&0;}int&pause(){ system(&pause&);&&&&&&&&&&&&&&&&&return&0;}int&switchs(double&a,double&b,char&s){&&&&&switch&(s) { case&'+':
printf(&a+b\n&);&&&&&&&&&&&&Sleep(500);
printf(&=%0.3lf+%0.3lf\n&,a,b);
Sleep(500);
printf(&=%0.3lf\n\007&,a+b);
Sleep(500);
} case&'-':
printf(&a-b\n&);
Sleep(500);
printf(&=%0.3lf-%0.3lf\n&,a,b);
Sleep(500);
printf(&=%0.3lf\n\007&,a-b);
Sleep(500);
} case&'*':
printf(&a*b\n&);
Sleep(500);
printf(&=%0.3lf*%0.3lf\n&,a,b);
Sleep(500);
printf(&=%0.3lf\n\007&,a*b);
Sleep(500);
} case&'/':
printf(&³ýÊý²»ÄÜΪ0£¡\n\007&);
Sleep(500);
printf(&a/b\n&);
Sleep(500);
printf(&=%0.3lf/%0.3lf\n&,a,b);
Sleep(500);
printf(&=%0.5lf\n\007&,a/b);
Sleep(500);
printf(&error!\n\007&);
Sleep(500);
} }R:;}int&main(void){&&&&&&&&char&c; double&a,b; char&s;R: printf(&\007please&input&a&formula:\n&); scanf(&%lf%c%lf&,&a,&s,&b); if(a==0||b==0||s=='\0')printf(&Error!&); else&switchs(a,b,s); pause(); while((c&=&getchar())&!=&'\n'&&&&c&!=&EOF); a=0;b=0;s='\0'; cls(); goto&R;}
提问者评价
其他类似问题
为您推荐:
c语言的相关知识
等待您来回答
下载知道APP
随时随地咨询
出门在外也不愁◇本站云标签求大神帮忙把程序改一下错误(用C语言设计一个简单的计算器)进行加减乘除,可带括号,不限定运算式的输入长度,多加些注释
[问题点数:100分,无满意结帖,结帖人qq_]
求大神帮忙把程序改一下错误(用C语言设计一个简单的计算器)进行加减乘除,可带括号,不限定运算式的输入长度,多加些注释
[问题点数:100分,无满意结帖,结帖人qq_]
不显示删除回复
显示所有回复
显示星级回复
显示得分回复
只显示楼主
相关推荐:
匿名用户不能发表回复!|
每天回帖即可获得10分可用分!小技巧:
你还可以输入10000个字符
(Ctrl+Enter)
请遵守CSDN,不得违反国家法律法规。
转载文章请注明出自“CSDN(www.csdn.net)”。如是商业用途请联系原作者。}

我要回帖

更多关于 c语言计算器代码 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信