




已阅读5页,还剩19页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
第 1 章C 语言概述 1 填空题 1 函数说明 函数体 2 声明区 主程序区 函数定义区 3 多态性 4 namespace using 5 std 6 cin 7 8 对数据的操作 2 判断题 1 对 2 错 3 错 4 错 5 错 3 改错题 1 没有函数体 应改为 void main 2 语句没有分号 应改为 using namespace myspace 3 cout 和操作符 共同完成输出的功能 应改为 cout Input your name 4 应改为 include 4 简答题 略 5 编程题 略 第 2 章基本数据类型 运算符与表达式 1 选择题 1 B 2 D 3 B 4 D 5 B 2 简答题 1 a c e f g h i 2 a g i j 3 a 5 5 b 0 c 20 d 0 0 e 1 f 1 2 g 3 h 40 i 2 j 3 k s1 0 side1 和 side2 为两条直角边长度 cout a b c 输入三角形三边长度 if a a b b c c c c a a b b b b a a c c 判断是否为直角三角形 if a a b b c c 判断三边中哪两条边为直角边 并存储到 side1 和 side2 中 side1 b side2 c else if c c a a b b side1 a side2 b else side1 a side2 c area side1 side2 2 计算直角三角形的面积 cout It is a right angled triangle and the area is area n 输出判断结果 及直角三角形面积 else cout It is not a right angled triangle n 2 编写程序 求解各种数据类型的存储长度并显示出来 在其中找出存储长度最大 的和最小的两种数据类型并输出 include void main int length 7 int max 0 min 0 cout data type tmemory used bytes length 0 sizeof short int 获取短整型长度 cout nshort int t length 0 t length 1 sizeof int 获取整型长度 cout ninteger t length 1 length 2 sizeof long 获取长整型长度 cout nlong integer t length 2 length 3 sizeof char 获取字符型长度 cout nchar t length 3 length 4 sizeof float 获取单浮点型长度 cout nfloat t length 4 length 5 sizeof double 获取双浮点型长度 cout ndouble t length 5 length 6 sizeof bool 获取布尔型长度 cout nbool t length 6 endl for int i 0 ilength max 求取长度最大的类型的存取位置 max i if length i length min 求取长度最小的类型的存取位置 min i cout The longest length is from switch max case 0 cout short int endl break case 1 cout int endl break case 2 cout long endl break case 3 cout char endl break case 4 cout float endl break case 5 cout double endl break case 6 cout bool endl break cout The shortest length is from switch min case 0 cout short int endl break case 1 cout int endl break case 2 cout long endl break case 3 cout char endl break case 4 cout float endl break case 5 cout double endl break case 6 cout bool endl break 3 编写程序输入一个华氏温度 将其转换为摄氏温度并输出 include void main float C 变量 C 为摄氏温度 float F 变量 F 为华氏温度 cout F 输入华氏温度 C F 32 5 9 华氏温度转换为摄氏度 cout 转换为摄氏温度为 C endl 4 编写程序输入一个十进制表示的正整数 将其转化为二进制表示并输出结果 include void main int a 变量 C 为摄氏温度 int b 20 数组存储转换后的二进制数 int i i 0 cout a 输入十进制数 while a 0 转换过程 b i a 2 i a int a 2 i cout 0 输出二进制结果 cout b i i cout endl 第 3 章C 的控制语句 1 选择题 1 B 2 A 3 A 4 C 5 A 2 判断题 1 错 2 对 3 对 4 错 5 错 3 读程序写结果 1 1 2 2 3 3 3 4 4 4 4 5 5 5 5 5 2 1 1 2 1 1 2 3 2 1 1 2 3 4 3 2 1 1 2 3 4 5 4 3 2 1 3 j 的值为 0 i 的值为 2 4 编程题 编写程序 计算 1 到 100 中所有 3 的倍数的数的和 include void main int sum 0 sum 变量为 3 的倍数的和 for int i 1 i 100 i if i 3 0 判断 i 是否是 3 的倍数 sum i cout 1 到 100 中所有 3 的倍数的数的和为 sum endl 编写程序 用户输入一些整数 该程序分别计算出所有奇数和所有偶数之和 并输 出它们 include void main int sum odd 0 变量为所有奇数的和 int sum even 0 变量为所有偶数的和 int b 变量为输入的数字 int N 变量为数字个数 cout N cout 请输入数字 数字以空格隔开 endl for int i 0 i b if b 2 0 判断数字是否为偶数 sum even b else sum odd b cout 所有奇数的和为 sum odd endl cout 所有偶数的和为 sum even endl 求解输入两个正整数的最大公约数和最小公倍数 include void main int a b 输入的两个正整数 int min max 最小值和最大值 cout 请输入两个正整数 数字以空格隔开 a b if a b 找出两个数中的最大值和最小值 min b max a else min a max b 最大公约数一定不大于两个数中的最小值 while min 0 if a min 0 else min cout a 和 b 的最大公约数为 min endl 最小公倍数一定不小于两个数中的最大值 while max a 0 max b 0 max cout a 和 b 的最小公倍数为 max endl 求解输入两个正整数的最大公约数和最小公倍数 include void main int a b 输入的两个正整数 int min max 最小值和最大值 cout 请输入两个正整数 数字以空格隔开 a b if a b 找出两个数中的最大值和最小值 min b max a else min a max b 最大公约数一定不大于两个数中的最小值 while min 0 if a min 0 else min cout a 和 b 的最大公约数为 min endl 最小公倍数一定不小于两个数中的最大值 while max a 0 max b 0 max cout a 和 b 的最小公倍数为 max endl 输入 4 个字母 并反向显示这些字母 include void main char a 4 输入 4 个字符 cout 请输入 4 个字符 endl for int i 0 i a i cout 反向输出 4 个字符为 0 i cout a i cout endl 输出所有的 水仙花数 水仙花数 是指一个 3 位数 其各位数字的立方和等于该数本身 include void main int N M int a 3 存储三位数的个十百位 cout 水仙花数为 endl for N 100 N 999 N M N for int j 0 j 3 j 提取数字的个十百位 a j M 10 M 10 if a 0 a 0 a 0 a 1 a 1 a 1 a 2 a 2 a 2 N cout N 求 1 2 50 include void main int sum1 1 记录 i 的结果 int sum2 0 记录 i 累加的结果 for int i 1 i 50 i for int j 1 j i j 计算 i sum1 j sum2 sum1 cout 1 2 50 sum2 endl 编写程序求一元二次方程 ax x bx c 0 的解 include include void main float a b c 方程的系数 float s1 s2 解 float temp cout Input a b c a b c if a 0 cout 不是一元二次方程 endl else temp b b 4 a c if temp 0 无根的情况 cout 无实根 endl else if temp 0 只有一个实根的情况 s1 b 2 a cout 方程有一个实根 为 s1 endl else 两个实根的情况 s1 b sqrt temp 2 a s2 b sqrt temp 2 a cout 方程有两个实根 为 s1 和 s2 endl 编写程序 用循环语句打印如下图案 include include include void main for int i 1 i 7 i cout setw abs 4 i 1 显示第一个 if i 1 i 7 第一行和最后一行仅显示一个 cout endl continue for int m abs 4 i 2 m 6 abs 4 i m 显示中间的 cout cout endl 中间几行显示第二个 编写程序 输入年月日信息 并输出这一天为这一年的第几天 注意闰年问题 include void main int year month day int num 0 int length cout year cout month cout day for int i 1 i month i if i 1 i 3 i 5 i 7 i 8 i 10 i 12 大月 31 天 length 31 else if i 4 i 6 i 9 i 11 小月 30 天 length 30 else if year 100 0 闰年的二月 29 天 else length 28 非闰年的二月 28 天 num length num day cout year 年 month 月 day 日为这一年的第 num 天 endl 编写程序 由用户输入 x 值 计算函数值并输出 y 函数如下所示 include void main int x y cout x if x 0 x10 x 10 的情况 y 4 x x x x x else 其余的情况 y x x cout 函数结果 y 为 y endl 鸡兔同笼问题 若鸡兔共有 100 只脚 利用循环计算鸡兔各几只 include void main int rabbit chicken for rabbit 100 4 rabbit 0 rabbit 兔子最多有 25 只 最少没有 chicken 100 rabbit 4 2 cout 兔子有 rabbit 只 鸡有 chicken 只 endl 第 4 章函数 1 填空题 1 void 2 静态全局变量 static 3 函数重载 4 inline 5 递归函数 6 宏定义命令 文件包含命令 条件编译命令 2 判断题 1 错 2 错 3 错 4 错 5 错 6 对 7 错 8 错 9 对 10 对 3 读程序写结果 1 x 7 y 4 x 9 y 5 2 34 56b 101 3 16 22 28 4 12 15 18 21 24 5 2 1 4 1 3 2 1 4 简答题 略 5 编程题 编写一个函数 计算直角坐标系中点 a x0 y0 到点 b x1 y1 的距离 include include float length float x0 float y0 float x1 float y1 求两点距离的子函数 return sqrt x0 x1 x0 x1 y0 y1 y0 y1 void main float x0 x1 y0 y1 cout x0 y0 cout x1 y1 cout The length from a to b is length x0 y0 x1 y1 endl 求 a b c 的值 其中求 n 要用一个函数实现 通过主函数输入 a b 和 c 的值 并 在主函数中输出计算的结果 include int factorial int n 求两点距离的子函数 int sum 1 for int i 1 i n i sum i return sum void main int a b c cout a b c cout a b c factorial a factorial b factorial c endl 编写一个函数 该函数读入一个整数 并判断这个整数是否为一个回文数字 例如 4 44 434 4334 43534 都是回文数字 include bool palindrome int n 判断 n 是否为回文的子函数 int a 20 int m n int i 0 int temp num while m 0 将数字的各位反向放置在数组 a 中 a i m 10 m m 10 i temp i 2 需要比较的次数 num i 数字的最高位存储在 a num 中 for int j 0 j temp j if a j a num j return false 如果出现不相等的情况立即退出 return true 若比较的各个位置都相等 则为回文 void main int number cout number if palindrome number cout number is a palindrome endl else cout number is not a palindrome endl 编写一个程序 为选修 3 4 和 5 门课程的学生计算平均分 其中求平均分要用重载 函数实现 include float average float a float b float c 求三门课程平均分子函数 return a b c 3 float average float a float b float c float d 求四门课程平均分子函数 return a b c d 4 float average float a float b float c float d float e 求五门课程平均分子函数 return a b c d e 5 void main int number float s1 s2 s3 s4 s5 cout number if number 3 cout s1 s2 s3 cout The average is average s1 s2 s3 endl else if number 4 cout s1 s2 s3 s4 cout The average is average s1 s2 s3 s4 endl else cout s1 s2 s3 s4 s5 cout The average is average s1 s2 s3 s4 s5 endl 用递归方法将一个整数 n 转换成字符串 include include using namespace std string convert int n string numstring void main int number cout number cout converted string is cout convert number endl string convert int n 递归函数 if n 10 0 else numstring convert n 10 append string 1 n 10 48 将各位数转换为字符后 创建字符串 加到最后 return numstring 编写一个函数 该函数读入一个整数 然后将这个整数上每个位的数字按照相反的 顺序输出 例如输入的整数为 12345 输出结果为 54321 include void reverse int n 反向显示整数 n int a 20 存储 n 的各位 最多 20 位 int m n int i 0 while m 0 提取 n 的各位 a i m 10 m m 10 i cout reversed number is for int j 0 j i 1 j 反向输出各位 cout a j cout endl void main int number cout number reverse number 输入三个数字 数字可以为整形或浮点型 分别编写函数来求解三个数字的最大值 最小值和平均值 要求在主函数中完成数字的输入和计算结果的输出 include include float fmax fmin faverage int max min average void calculate float fa float fb float fc 浮点型处理函数 fmax fa fb fa fb fmax fmax fc fmax fc fmin fa fb fa fb fmin fmin b a b max max c max c min a b a b min min c min c average a b c 3 void main int s1 s2 s3 float f1 f2 f3 int type cout type while type 0 cout f1 f2 f3 calculate f1 f2 f3 cout setw 8 max setw 8 min setw 12 average endl cout setw 8 fmax setw 8 fmin setw 12 faverage s1 s2 s3 calculate s1 s2 s3 cout setw 5 max setw 8 min setw 8 average endl cout setw 5 max setw 8 min setw 8 average endl 第 5 章构造数据类型 1 选择题 1 C 2 D 3 A 4 B 5 C 2 判断题 1 错 2 对 3 对 4 错 5 错 3 读程序写结果 1 153 2 42 25 6 8 10 3 65535 21 4 4 19 5 6904 6 4 3 2 1 0 4 编程题 编写函数 完成指定二维数组 3 3 的转置 即行列对换 include include void main int i j temp row 0 colum 0 int a 3 3 cout 输入一个 3 3 的整型矩阵 endl for i 0 i 2 i 从第 0 行 第 2 行 for j 0 j a i j 输入矩阵元素 for i 0 i 2 i for j 0 j i j 将 a i j 与 a j i 的值互换 temp a i j a i j a j i a j i temp for i 0 i 2 i for j 0 j 2 j cout setw 8 a i j 输入矩阵元素 cout endl 编写一个程序 要求当输入一个数字月份时 程序输出该月的英文名称 例如输入 5 时 程序输出 May 要求用指针数组实现 include include void main 定义指针数组 char month 12 January February March April May June July August September October November December int n cout n while n 12 n 1 cout n cout The month is month n 1 endl 编写一个程序 要求分别输入 5 个学生的 3 科成绩 并输出平均成绩最高的学生的 姓名及各科成绩 要求用结构体数组实现 include include struct student char name 20 姓名 float course1 第一科成绩 float course2 第二科成绩 float course3 第三科成绩 float average 平均成绩 struct student stu 5 void main float temp 100 0 int j k 0 char c for int i 0 i 5 i cout Input NO i 1 stu i name cout Input NO i 1 stu i course1 stu i course2 stu i course3 输入三科成绩 stu i average stu i course1 stu i course2 stu i course3 3 求平均成绩 if temp stu i average temp stu i average temp 存放最高平均分 k i k 存放该同学的序号 cout The student is stu k name three scores are stu k course1 stu k course2 and stu k course3 endl 编写一个程序 实现方程式的相加 include include struct coefficient bool pn int num a 3 b 3 c 3 d 3 void main char equation 2 50 ch z 8 int m j cout Input NO 1 Equation equation 0 cout In
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 桥梁养护知识培训课件
- 2026届甘肃省兰州市兰州第一中学高一化学第一学期期中预测试题含解析
- 2026届江西省吉安市安福中学化学高二第一学期期末质量检测模拟试题含答案
- 2025年客户服务经理面试技巧全解析高级模拟题及答案
- 2025年陪诊师考试重要提示与试题及答案
- 投标文件中售后应急预案方案
- 2025年城市经济与可持续发展课程考试题及答案
- 2025年环保技术与可持续发展相关考试题及答案
- 2025年村级儿童之家档案员招聘考试重点回顾
- 公务员转任面试题目及答案
- 传播游戏理论视域下现代文创桌游传播伦理失范与匡正研究
- 2025年家畜饲养员及繁殖学技能资格知识考试题与答案
- 中国都市圈综合竞争力报告2024-上海同济城市规划设计研究院
- 意大利足协协议书
- 减重代谢外科个案管理体系构建
- 喷雾降尘合同协议
- CNAS-CC121-2017 环境管理体系审核及认证的能力要求
- 沙石购买合同协议
- 小学生依法治国课件
- 食堂自带碗筷管理制度
- 延期退休协议书范本
评论
0/150
提交评论