版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、程序填空题1、下列程序计算 1000 以内能被 3 整除的自然数之和。#include using namespace std; void main( ) int x=1, sum; sum=0; while (true) if (x1000) break; if (x%3=0) sum+=x; x+;coutsumendl;2. 以下程序段的功能是判断 m 是否为素数,请将程序补充完整。#include #include using namespace std; void main() int m,i,k; cinm; k=sqrt(float(m);for(i=2;ik) coutd” i
2、saprimenumbern”mendl;elsecoutd” isnotaprimenumbern”mendl;三、写出程序的运行结果1.假定输入 10 个整数:32,64,53,87,54,32,98,56,98,83。下列程序的输出结果是?#include using namespace std; void main( ) int a,b,c,x; a=b=c=0;for (int k=0; kx; switch(x%3) case 0: a+=x; break; case 1: b+=x; break; case 2: c+=x; break;couta”,”b”,”cendl;结果:
3、141,64,4522. 写出程序的运行结果#include using namespace std; void main( ) int j,k;for (j=5; j0; j-) for (k=j; k0; k-) cout”*”; coutendl;结果:*编程题1、 编写程序,求解方程 ax2+bx+c=0 的根。#include #include using namespace std; void main()int a,b,c; float x1,x2,z;cinabc; z=b*b-4*a*c; if(z0)x1=(-b)+sqrt(z)/(2*a);x2=(-b)-sqrt(z)
4、/(2*a);coutthe result: x1=x1 x2=x2endl;else if(z=0)x1=-b/(2*a);coutthe result: x1=x1endl;elsecoutno result;2、 编写程序输出所有的水仙花数。所谓水仙花数是指一个三位数,其各位数的立方和等于该数。例如:153=13+53+33。#include using namespace std; void main()int a,b,c;for(int i=100;i=999;i+)a=i/100; b=i%100/10; c=i%10;if(a*a*a+b*b*b+c*c*c=i) coutien
5、dl;3、 编写程序,计算 s=1+(1+2)+(1+2+3)+(1+2+3+n)的值。#include using namespace std; void main()int n,s,sum=0; cinn;for(int i=1;i=n;i+) s=0;for(int j=1;j=i;j+) s+=j;sum+=s;coutsumendl;第 4 章 数组和字符串一、写出程序的运行结果1. #include using namespace std; void main() char s180,s240;int i=0,j=0; cins1; cins2; while(s1i!=0)i+;w
6、hile(s2j!=0)s1i+=s2j+;s1i=0;cout“the new string is : ”s1;答案( 将两个字符串首尾相连)2. #includeusing namespace std;void main() int max_value(int array 4);int a34=1,3,5,7,2,4,6,8,15,17,34,12;coutmax_value(a);int max_value(int array 4) int i,j,max;max=array00; for(i=0;i3;i+)for(j=0;jmax)max=arrayij;return(max);答案
7、(求数组中的最大值)3. #include #includeusing namespace std;void main() char string81;int i,num=0,word=0; char c;gets(string); for(i=0;(c=stringi)!=0;i+)if(c= ) word=0; else if(word=0)word=1; num+;cout“there arewords in the line.”num;程序运行中输入:i am a boy.(表示回车)答案(there arewords in the line.4)4. #includeusing na
8、mespace std;void main() int a33,sum=0; int i,j; for(i=0;i3;i+)for(j=0;jaij; for(i=0;i3;i+)sum=sum+aii; cout“sum=”sumendl;程序运行中输入:123456789 (表示回车)答案(15对角线元素的和)第 6 章函数二. 读下列程序,写出运行结果1.#include using namespace std; int add(int x,int y)cout”in add(),received”x”and”yendl; cout”and return”x+yendl;return x
9、+y;void main()int a,b,c;coutab; cout”ncalling add():n”; c=add(a,b);cout”nback in main():n”; cout”c was set to “cendl; cout”nexit n”;2. #include using namespace std;void add_1(int x)x+; void add_2(int &x)x+; void add_3(int *p)(*p+;void main() int a=2; add_1(a);coutaendl; 输出的结果为: 2 add_2(a);coutaendl;
10、 输出的结果为:3 add_3(&a);coutaendl; /输出的结果为:4 3. #include using namespace std; const intn=6; int fun(int k) int result; if(k=1)result=1; elseresult=2*fun(k-1); return result;void main( ) int a=3,res=0; res=n/a;coutresendl; /输出结果为:2res=fun(a);coutresendl; /输出结果为:44. 下面程序的输出结果是(14 )#include using namespace
11、 std; int i = 0;int fun(int n)static int a = 2; a+;return a+n;void main()int k = 5;int i = 2;k += fun(i);k += fun(i); cout k;5. 以下程序的输出结果是:(3 )#include using namespace std; intfun(char *s)char *p=s;while (*p!=0)p+; return (p-s);void main() coutfun(abc)endl;6. #include using namespace std; int f(int
12、a)return +a;int g(int& a) return +a;void main()int m=0,n=0; m+=f(g(m);n+=f(f(n); coutm=mendl; coutn=nendl;运行结果:m=3 n=2“”“”at the end, xiao bian gives you a passage. minand once said, people who learn to learn are very happy people. in every wonderful life, learning is an eternal theme. as a professi
13、onal clerical and teaching position, i understand the importance of continuous learning, life is diligent, nothing can be gained, only continuous learning can achieve better self. only by constantly learning and mastering the latest relevant knowledge, can employees from all walks of life keep up with the pace of ente
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2026届河南省南阳市高三上学期期末质量评估历史试题(含答案)
- 食物中毒及预防考试答案
- 2025 小学三年级科学下册保护动物多样性的意义课件
- 《GAT 953-2011法庭科学枪口比动能测速仪法测试规程》专题研究报告
- 《GAT 718-2007枪支致伤力的法庭科学鉴定判据》专题研究报告深度
- 2026年深圳中考语文考场实战模拟试卷(附答案可下载)
- 采购试卷题目及答案
- 2026年深圳中考数学命题趋势预测试卷(附答案可下载)
- 雅思全真冲刺题库及答案
- 2026年深圳中考历史拔尖培优特训试卷(附答案可下载)
- 北京市通州区2024-2025学年八年级下学期学业质量检测生物考试题目及答案
- 雅诗兰黛新人培训
- 2025年高考(甘肃卷)地理真题(学生版+解析版)
- 后勤副校长述职课件
- 中医男科学理论知识考核试题及答案
- 中移动薪酬管理办法
- GB/T 45758-2025室内照明环境下光催化材料细菌减少率的测定半干法估算实际环境细菌污染表面抗菌活性
- 护理教学如何融入思政
- 宫腔镜手术并发症的预防与处理
- 放疗患者的饮食指导及护理
- 工程投标工作汇报
评论
0/150
提交评论