




已阅读5页,还剩11页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
实实 验验 报报 告告 第一题 从键盘上输入一个整数第一题 从键盘上输入一个整数 n n 的值 按下时求出的值 按下时求出 y y 的值 的值 并输出并输出 n n 和和 y y 的值的值 Y 1Y 1 2 2 3 3 n n 源程序清单 源程序清单 include include voidvoid mainmain intint t 1 n y 0 t 1 n y 0 cout n n cout n n cin n cout n n n cout n n n for intfor int i 1 i n i i 1 i n i t t i t t i y y t y y t cout y y endl cout y y endl 运行结果 运行结果 第二题 设计一个程序 求出第二题 设计一个程序 求出 100 10000100 10000 之间的所有之间的所有 素数 素数 源程序清单 源程序清单 include include include include voidvoid main main intint i n count 0 i n count 0 for n 101 n 1000 n for n 101 n 1000 n for i 2 i n 1 i for i 2 in 1 if i n 1 cout setw 4 n cout setw 4 n count count if count 10 0 if count 10 0 cout endl cout endl cout endl cout endl 运行结果 第三题 设计一个程序 输入一个任意整数 第三题 设计一个程序 输入一个任意整数 1 41 4 位 位 求出各位数字之和 并统计出位数 求出各位数字之和 并统计出位数 源程序清单 源程序清单 include include voidvoid main main intint n k s 0 t 0 n k s 0 t 0 cout n endl cout n n cin n while n while n k n 10 k n 10 n n 10 n n 10 s s k s s k t t 1 t t 1 cout s t t endl cout s t t rm r 分别求出 分别求出 C C 4 24 2 C C 6 6 4 4 C C 8 78 7 的值 要求用函数来实现求 的值 要求用函数来实现求 阶乘和组合数 在主函数中测试 阶乘和组合数 在主函数中测试 源程序清单 源程序清单 include include include include floatfloat f intf int n n if n 0 if n 0 cout ncout n 应为正数应为正数 n n floatfloat s s if n 1 n 0 if n 1 n 0 returnreturn 1 1 elseelse s n f n 1 s n f n 1 returnreturn s s floatfloat c intc int m intm int r r if m r if m r cout mcout m r cin m r cout c m r c m r cout c m r c m r n 运行结果 运行结果 第五题 设计一个程序 用筛选法求出第五题 设计一个程序 用筛选法求出 3 1003 100 之间的所有之间的所有 素数 要求每行输出素数 要求每行输出 5 5 个素数 判断一个整数是个素数 判断一个整数是 否为素数应设计一个函数来实现 否为素数应设计一个函数来实现 源程序清单 源程序清单 include include include include intint fun intfun int n n for intfor int i 2 i n i i 2 i n i if n i 0 returnif n i 0 return 0 0 returnreturn 1 1 voidvoid main main intint count 0 count 0 for intfor int i 3 i 100 i i 3 i 100 i if fun i if fun i cout i setw 4 cout i setw 4 count count if count 5 0 cout n if count 5 0 cout n cout n cout n 运行结果 运行结果 第六题 把二维数组第六题 把二维数组 a a 赋值给赋值给 b b 并把 并把 b b 中元素的值等于中元素的值等于 a a 中对应元素的平方 中对应元素的平方 源程序清单 源程序清单 include include include include voidvoid main main intint a 3 4 b 3 4 i j a 3 4 b 3 4 i j for i 0 i 3 i for i 0 i 3 i for j 0 j 4 j for j 0 j a i j cin a i j for i 0 i 3 i for i 0 i 3 i for j 0 j 4 j for j 0 j 4 j b i j a i j a i j b i j a i j a i j for i 0 i 3 i for i 0 i 3 i for j 0 j 4 j for j 0 j 4 j cout b i j t cout b i j t cout n cout n 运行结果 运行结果 第七题 下面的程序求出第七题 下面的程序求出 10001000 以内的孪生质数的对数 改以内的孪生质数的对数 改 错题 错题 源程序清单 源程序清单 include include include include include include intint isprime intisprime int x x intint k i k i k int sqrt x k int sqrt x for i 2 i k i for i 2 i k i if x i 0 if x i 0 return 0 return 0 return 1 return 1 voidvoid main main intint a 500 count k 0 a 500 count k 0 intint b 35 2 b 35 2 for intfor int i 3 i 1000 i 2 i 3 i 1000 i 2 if isprime i a k i if isprime i a k i count 0 count 0 for i 0 i k 1 i for i 0 i k 1 i if a i 1 a i 2 if a i 1 a i 2 b count 0 a i b count 0 a i b count 1 a i 1 b count 1 a i 1 for i 0 i count i for i 0 i count i if i 5 0 cout n if i 5 0 cout n cout setw 3 b i 0 setw 3 b i 1 t cout setw 3 b i 0 setw 3 b i 1 t cout endl count count endl cout endl count count endl 运行结果 运行结果 第八题 有两个字符串 将主字符串中的所有子字符串删第八题 有两个字符串 将主字符串中的所有子字符串删 去并输出 例如 主字符串为去并输出 例如 主字符串为 This This isis a a veryvery goodgood book book 子字符串为 子字符串为 book book 结果为 结果为 This This isis a a veryvery good good 源程序清单 源程序清单 include include include include intint withstr charwithstr char s1 char s1 char subs subs while subssubs s1 subs returnreturn subs subs charchar delsub char delsub char s1 char s1 char subs subs charchar p1 p2 p1 p2 intint len strlen subs len strlen subs p2 p1 s1 p2 p1 s1 while p1 while p1 if withstr p1 subs p1 len if withstr p1 subs p1 len elseelse p2 p1 p2 p1 p2 0 p2 0 returnreturn s1 s1 voidvoid main main charchar str1 80 Thisstr1 80 This isis a a veryvery goodgood book book charchar str2 40 book str2 40 book cout str1 endl str2 endl cout str1 endl str2 endl cout delsub str1 str2 endl cout delsub str1 str2 endl 运行结果 第九题 设计一个通用函数查询一个带通配符第九题 设计一个通用函数查询一个带通配符 的字符串在另的字符串在另 一个字符串中出现的次数 在主程序中进行测试 一个字符串中出现的次数 在主程序中进行测试 源程序清单 源程序清单 include include intint fun char strfun char str char searchar sear intint p1 p1 p1 str p1 p1 if p1 9 if p1 9 for charfor char p2 p1 p2 p2 p2 p1 p2 p2 p2 p2 1 p2 p2 1 if p1 9 p1 if p1 9 p1 returnreturn str str intint vale charvale char str str intint s 0 s 0 charchar p str strlen str 1 p str strlen str 1 for p str p for p str p s s 10 p 0 s s 10 p 0 returnreturn s s voidvoid main main charchar s 3fgh21 78UI s 3fgh21 78UI cout s endl cout s endl cout del s endl cout del s endl cout vale s endl cout vale s endl 运行结果为 运行结果为 第十一题 已知函数第十一题 已知函数 voidvoid stat char 3 intstat char 3 int i char p char p num aphlet other 0 num aphlet other 0 for i 0 i 3 i for i 0 i 3 i p s i p s i cout s i 1 cout s i 1 p endl p 0 elseelse other other p p voidvoid main main char s 3 1char s 3 1 Ab12c Ab12c intint n a o n a o stat s n stat s n cout num n endl cout num n endl cout aphlet a endl cout aphlet a endl cout other o endl cout other o endl 运行结果为 运行结果为 第十二题 建立一个类第十二题 建立一个类 SUMSUM 求一个二维数组外围各元素之和 并 求一个二维数组外围各元素之和 并 输出数组中各元素所求之和 具体要求如下 输出数组中各元素所求之和 具体要求如下 1 1 私有数据成员 私有数据成员 intint array 5 5 array 5 5 二维整型数组二维整型数组 intint s s 数组数组 arrayarray 各外围元素之和各外围元素之和 2 2 公有成员函数 公有成员函数 SUMSUM intint d 5 5 d 5 5 构造函数 初始化成员数据构造函数 初始化成员数据 voidvoid process process 求二维数组外围元素之和求二维数组外围元素之和 s s voidvoid printprint 输出二维数组 每行输出五个元素 及其外围元素输出二维数组 每行输出五个元素 及其外围元素 之和之和 3 3 在主程序中对该类进行测试 使用如下测试数据 在主程序中对该类进行测试 使用如下测试数据 外围元素 外围元素 是指阴影部分的元素 是指阴影部分的元素 源程序清单 源程序清单 include include classclass SUM SUM intint array 5 5 array 5 5 intint s s public public 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 1010 1111 1212 1313 1414 1515 1616 1717 1818 1919 2020 2121 2222 2323 2424 2525 SUM intSUM int d 5 5 d 5 5 voidvoid process process voidvoid print print SUM SUM intSUM SUM int d 5 5 d 5 5 forfor int int i 0 i 5 i i 0 i 5 i forfor int int j 0 j 5 j j 0 j 5 j arrayarray i j d i j i j d i
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025-2030中国快锁接头海外市场拓展战略与本土化运营案例分析报告
- 2025-2030中国宠物医疗连锁机构并购扩张与专科化服务趋势
- 综合复习与测试说课稿-2025-2026学年初中英语新世纪版八年级第二学期-新世纪版试用本
- 2025-2030中国城市青年住房支付能力与租金定价模型
- 2025-2030中国单身经济背景下迷你家电市场趋势研究
- 2025-2030中国养老康复辅具市场需求与产品创新方向
- 2025-2030中国共享居住业态发展趋势与青年公寓转型路径研究
- 2025-2030中国公寓公共空间利用率及功能设计报告
- 2025-2030中国互联网医疗医保支付突破与分级诊疗协同发展报告
- 2025-2030中国mRNA疫苗技术平台扩展应用与本土企业研发管线
- 场景速写课件
- GPS的课件教学课件
- 2026年高考作文备考之抗日战争胜利80周年(九三阅兵)主题素材积累与运用
- 肺栓塞考试题及答案
- 2025年运动员:体育与健康知识试题及答案
- 综合实践 探索年月日的秘密(教案)北师大版数学三年级上册
- 2025年医师三基考试试题及答案(上半年)
- 2025年调酒师职业资格考试模拟试题集锦及答案
- 基孔肯雅热主题班会课件
- 2025年北京市公务员考试行测真题及答案详解(全优)
- 锁骨下盗血综合征伴锁骨下动脉闭塞的护理查房
评论
0/150
提交评论