⽤switch编写计算器php,⽤switch语句编程设计⼀个简单的计
算器程序
公告: 为响应国家净⽹⾏动,部分内容已经删除,感谢读者理解。
话题:⽤switch语句编程设计⼀个简单的计算器程序回答:#include stdio.hint main( ){ double a, b; char op; scanf("%lf%c%lf", a, op, b); switch (op) { case '+': printf("%lf + %lf = %lf\n", a, b, a + b); break; case '-': printf("%lf - %lf = %lf\n", a, b, a - b); break; case '*': printf("%lf * %lf = %lf\n", a, b, a * b); break; case '/': if (b != 0) printf("%lf / %lf = %lf\n", a, b, a / b); else printf("除数不能是0! \n"); break; }}话题:⽤switch语句编程设计⼀个简单的计算器程序回答:#include stdio.h int main( ) { double a, b; char op; scanf("%lf%c%lf", a, op, b); switch (op) { case '+': printf("%lf + %lf = %lf\n", a, b, a + b); break; case '-': printf("%lf - %lf = %lf\n", a, b, a - b); break; case '*': printf("%lf * %lf = %lf\n", a, b, a * b); break; case '/': if (b != 0)
printf("%lf / %lf = %lf\n", a, b, a / b); else printf("除数不能是0! \n"); break; } }话题:⽤switch语句实现程序(C语⾔)回答:
#includechar fun(float a,float b);int main(void){char ch;float score1,score2;printf("enter the student's s
core(q to quit) :\n ");while(scanf("%f%f",score1,score2) == 2){ch = fun(score1, score2);switch(ch){case 'A':printf("%f -----%c\n",score1 + score2,ch);break;case 'B':printf("%f -----%c\n",score1 + score2,ch);break;case 'C':printf("%f -----%c\n",score1 +
score2,ch);break;case 'D':printf("%f -----%c\n",score1 + score2,ch);break;case 'E':printf("%f -----%c\n",score1 +
score2,ch);break;default:break;}}printf("\n");return 0;}char fun(float a,float b){char chr;if(a + b 10)chr = 'A';else if((a+b) 160 (a+b) chr = 'B';else if((a+b) 140 (a+b) chr = 'C';else if((a+b) 120 (a+b) chr = 'D';else if((a+b) chr = 'E'; return chr;}注意 输⼊分数时 必须以浮点型输⼊,如0.0 1.5 不能这样 0 1看不懂别⼈的程序就说不对呀 呵呵 空城笑影的程序太不了⽽且写程序的⽅式不符合范,是看谭浩强养成的病吧 最好到好的看看 还有⽤ void main() 的吗 int sum = a + b;这句你能编译出来很厉害啊 说明你⽤的编译器⽀持 c 可你写的程序通⽤不怎么样啊 其他不说了 个⼈认为不怎么样啊
参考回答:#include void main(){int a,b;printf("请输⼊两门成绩的分数\n");scanf("%d,%d",a,b);int sum=a+b;switch(sum) {case (sum=10):printf("%d----A",sum);case (sum=160)(sumprintf("%d----B",sum);case (sum=140)(sumprintf("%d----C ",sum);case (sum=120)(sumprintf("%d----D",sum);case (sumprintf("%d----E",sum);}}话题:使⽤switch语句设计程序,输⼊两个数a,b,当输
⼊字符c分别为+,回答:#include lt;iostreamgt;#include lt;stringgt;using namespace std;int main(){int a,b;char
c;coutlt;lt;"输⼊两个数a,b"lt;lt;endl;cinab;cinc;switch(c){case '+':coutlt;lt;alt;lt;"+"lt;lt;blt;lt;"="lt;lt;a+blt;lt;endl;break;case '-':coutlt;lt;alt;lt;"-"lt;lt;blt;lt;"="lt;lt;a-blt;lt;endl;break;case '*':coutlt;lt;alt;lt;"*"lt;lt;blt;lt;"="lt;lt;a*blt;lt;endl;break;case '/':if (b==0) coutlt;lt;"除数不能为!"lt;lt;endl;elsecoutlt;lt;alt;lt;"/"lt;lt;blt;lt;"="lt;lt;a/blt;lt;endl;break;}return 0;}
参考回答:#includelt;stdio.hgt;void main(){int a,b;char c;scanf("%d%c%d",amp;a,amp;c,amp;b);switch(c){case
'+':printf("%d+%d=%d",a,b,a+b);break;case '-':printf("%d-%d=%d",a,b,a-b);break;case '*':printf("%d*%d=%d
",a,b,a*b);break;case '/':printf("%d/%d=%d",a,b,a/b);break;}}话题:c语⾔程序设计 switch语句的应⽤回答:#includelt;stdio.hgt; void main() { int n; float a,b; float gain,bonus=0; scanf("%f",amp;gain); if(gaingt;=0amp;amp;gainlt;=100000) n=100; else if(gainlt;=200000) n=5; else if(gainlt;=400000) n=50; else if(gainlt;=600000) n=30; else if(gainlt;=1000000) n=15; else
if(gaingt;1000000) n=10; switch(n) { case 100:a=0;b=0;break; case 5:a=10000;b=100000;break; case
50:a=1500;b=200000;break; case 30:a=2500;b=400000;break; case 15:a=33500;b=600000;break; case
10:a=3500;b=1000000;break; } bonus=a+(gain-b)*n/1000; printf("%.2f\n",bonus); }
参考回答:先列个表,然后弄个速算扣除,类似阶梯个税计算表,就可以⽤switch语句来做话题:使⽤switch语句编写 程序回答:
#include "stdio.h"#include "iostream.h"void main(){int age; 定义年龄coutlt;lt;"请输⼊你的年龄:";cinage; 输⼊年龄switch(age){case 1:{coutlt;lt;"你1岁已被分到⼉园⼩班"lt;lt;endl;break;}case 2:{coutlt;lt;"你2岁已被分到⼉园⼩班"
lt;lt;endl;break;}case 3:{coutlt;lt;"你3岁已被分到⼉园⼩班"lt;lt;endl;break;}case 4:{coutlt;lt;"你4岁已被分到⼉园中班"
lt;lt;endl;break;}case 5:{coutlt;lt;"你5岁已被分到⼉园⼤班"lt;lt;endl;break;}case 6:{coutlt;lt;"你6岁已被分到⼉园⼤班"
lt;lt;endl;break;}}}话题:运⽤SWITCH语句编写程序回答:#include int main() { int x;printf("请输⼊分数:");scanf("%d
",amp;x);switch(x/10){case 10:case :printf("A");break;case :printf("B");break;case :printf("C");break;case 6:printf("D ");break;default:printf("E");}return 0;}
参考回答:#include int main() { int x; coutlt;lt;"请输⼊分数:"; cinx;switch(x/10) { case 10:case :coutlt;lt;"A";break; case :coutlt;lt;"B";break; case :coutlt;lt;"C";break; case 6:coutlt;lt;"D";break; default:coutlt;lt;"E";} coutlt;lt;endl;return 0; }话题:⽤switch语句编程设计⼀个简单的计算器程序,要求根据从键盘输回答:#includelt;stdio.hgt;int main(){char
c='o';while(c=='o'||c=='Y'){float x,y; 第⼀问中的浮点数我默认为单精度 若是双精度 记得scanf中的格式改成对应的lf char
optor;printf("please input the expression:\n");scanf("%f %c %f",amp;x,amp;optor,amp;y); 解决第⼀、⼆问的关键 scanf的格式需要改对应float型的f fflush(stdin); 清除缓存,相当于清除上⼀个回车 switch(optor) 为什么我的scanf中%f和%c中间需要加空格? 因为需要满⾜第⼆问的要求 这⾥涉及到scanf语句的运⽤ { 我贴出很好的⼀个来解释scanf中为什么要加空格的问题 s:
switch语句必须使用break吗blog.csdn./shuimanting520/article/details/5214 case '+':printf("%f+%f=%f\n",x,y,x+y);break;case '-':printf("%f-%f=%f\n ",x,y,x-y);break;case '*':printf("%f*%f=%f\n",x,y,x*y);break;case '/':if(y==0) 利⽤if判断解决第⼀问中被除数不能为0的问题{printf("data error!\n");}else{printf("%f/%f=%f\n",x,y,x/y);}break;default:printf("input error!"); }printf("Do you want to continue?(Y/N)\n");scanf("%c",amp;c);while(c!='Y'amp;amp;c!='N'){ printf("Please retype the letters(Y/N)\n
");fflush(stdin); 清除缓存,相当于清除上⼀个回车 scanf("%c",amp;c);}}return 0;}话题:⽤switch语句写⼀段程序回答:
#includelt;stdio.hgt; main() { int a,mark; printf("请输⼊分数mark="); scanf("%d",amp;mark); a=mark/10; switch(a) { case 10: case : printf("成绩等级A");break; case : printf("成绩等级B");break; case : printf("成绩等级C");break; case 6: printf("成绩等级D");break; case 5: case 4: case 3: case 2: case 1: case 0:printf("成绩等级E");break; } getch(); }
参考回答:if(gradegt;=0) score='1'; else if(gradegt;=0) score='2'; else if(gradegt;=0) score='3'; else if(gradegt;=60) score='4'; else score='5'; switch(score) { case '1' : printf("A"); break; case '2': printf("B"); break; case '3': printf("C"); break; case '4': printf("D"); break; case '5': printf("E"); break; default: printf("error!"); }话题:⽤switch语句实现程序(C语⾔)回答:
#includestdio.hchar fun(float a,float b);int main(void){ char ch; float score1,score2; printf("enter the student's score(q to quit) :\n"); while(scanf("%f%f",score1,score2) == 2) { ch = fun(score1, score2); switc
参考回答:展开全部 #includestdio.hchar fun(float a,float b);int main(void){ char ch; float score1,score2; printf("enter the student's score(q to quit) :\n"); while(scanf("%f%f",score1,score2) == 2) { ch = fun(score1, score2); switch(ch) { case
'A': printf("%f ----- %c\n",score1 + score2,ch); break; case 'B': printf("%f ----- %c\n",score1 + score2,ch); break; case 'C': printf("%f ----- %c\n",score1 + score2,ch); break; case 'D': printf("%f ----- %c\n",score1 + score2,ch); break; case 'E': printf("%f ----- %c\n",score1 + score2,ch); break; default:break; } } printf("\n"); return 0;}char fun(float a,float b){ char chr; if(a + b 10) chr = 'A'; else if((a+b) 160 (a+b) 1 ) chr = 'B'; else if((a+b) 140 (a+b) 15 ) chr = 'C'; else if((a+b) 120 (a+b) ) chr = 'D'; else if((a+b) 120 ) chr = 'E'; return chr;}注意 输⼊分数时 必须以浮点型输⼊,如0.0 1.5 不能这样 0 1看不懂别⼈的程序就说不对呀 呵呵 空城笑影的程序太不了⽽且写程序的⽅式不符合范,是看谭浩强养成的病吧 最好到好的看看 还有⽤ void main() 的吗 int sum = a + b;这句你能编译出来很厉害啊 说明你⽤的编译器⽀持 c 可你写的程序通⽤不怎么样啊 其他不说了 个⼈认为不怎么样啊
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论