实验二、选择结构程序设计_第1页
实验二、选择结构程序设计_第2页
实验二、选择结构程序设计_第3页
实验二、选择结构程序设计_第4页
实验二、选择结构程序设计_第5页
全文预览已结束

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

实验二实验二 选择结构程序设计选择结构程序设计 一 实验目的一 实验目的 1 掌握关系表达式和逻辑表达式的使用 2 熟悉选择结构程序设计 3 熟练使用 if 语句进行程序设计 4 使用 switch 语句实现多分支选择结构 二 实验内容二 实验内容 2 编写一个程序 其功能为 输入三个整数分别保存在 a b c 三个变量中 通过比较和交换 使得最终 a b c 三个变量中的值依次由小到大排列 要求 分别输出排序前和排序后 a b c 中的值 方法一 include void main int a b c t printf 请输入三个整数 a b c n scanf d d d printf 排序前的三个整数为 ta d tb d tc d n a b c if a b t a a b b t if b c t b b c c t if a b t a a b b t else if b c t b b c c t if a b t a a b b t printf 排序后的三个整数为 ta d tb d tc d n a b c 方法二 include void main int a b c t printf 请输入三个整数 a b c n scanf d d d printf 排序前的三个整数为 ta d tb d tc d n a b c if a b t a a b b t if b c t b b c c t if a b t a a b b t printf 排序后的三个整数为 ta d tb d tc d n a b c 4 有如下分段函数 要求编写一个程序 输入自变量的 x 值 计算并输出函数 的值 y x 5x 0 0X 0 12 x 0 x 10 3x 11 X 10 include include void main float x y printf 请输入 x n scanf f if x 0 else y 3 x 11 printf y f n y 5 编写一个程序 其功能为 从键盘输入一个字符 判别该字符属于数字字符 大写字母 小写字母 其它字四个的类别中的哪个类别 并输出相应的信息 include stdio h void main char ch printf 请输入一个字符 n scanf c if ch 0 else printf 输入的是其他字符 n 6 编程在屏幕上显示一张如下所示的时间表 Time 1morning 2afternoon 3night Please enter your choice 根据用户输入的时间序号显示相应的问候信息 选择 1 时显示 Good morning 选择 2 时显示 Good afternoon 选择 3 时显示 Good night 对 于其他选择显示 Selection error include stdio h void main int xh printf n n Time n printf 1 morning n printf 2 afternoon n printf 3 night n printf n n 请输入您的选择 1 2 3 scanf d switch xh case 1 printf nGood morning n break case 2 printf nGood atfernoon n break case 3 printf nGood night n break default printf nSelection error n break 8 编写一个实现简单算术表达式计算的程序 从键盘输入的表达式格式如下 操作数 1 运算符 op 操作数 2 要求计算并按照指定格式输出表达式 可实现的运算包括加 减 乘 除 输入输入 Please enter the expression 22 12 12 10 输出输出 22 12 12 10 34 22 方法一 include void main float x y z char op printf 请输入表达式 scanf f c f if op z x y if op z x y if op z x y if op if y 0 z x y else printf 除数为 0 n if y 0 printf f c f f n x op y z 方法二 include void main float x y z char op printf 请输入表达式 scanf f c f switch op case z x y break case z x y break

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论