- 47
- 0
- 约7.1千字
- 约 47页
- 2016-06-30 发布于河南
- 举报
《例题字母译码输入一个小写字母,输出其后的第四个字符》.ppt
第四章 选择结构程序设计 4.1关系运算符及表达式 4.2 if语句 4.2 逻辑运算符及表达式 4.3if语句的其他形式 (2)if语句的其他形式 (★if语句的嵌套) 内容回顾 4.4 switch 语句 三、break语句 课程回顾 例题:编写一个四则运算的运算器。具体要求:输入一个四则运算计算式,计算机给出相应的结果。 (operation.c) #include stdio.h void main() { …… } int x,y;char c; printf(input an arithmatic operation:a+(-,*,/)b\n); scanf(%d%c%d,x,c,y); 输入运算式 c==‘+’ 输出x+y y 输出x-y n c==‘*’ y n c==‘-’ y 输出x*y n c==‘/’ y 输出x/y n 提示“错误” if(c==+) printf(%d\n,a+b); else if(c==-) printf(%d\n,a-b); else else else if(c==‘*) if(c==‘/) printf(%d\n,a*b); printf(%d\n,a/b); printf(“ 错误的表达式\n”); 本节重点:1)if语句与switch语句的关系。
原创力文档

文档评论(0)