版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
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山东潍坊市教育局所属学校急需紧缺人才及部属公费师范生招聘22人备考笔试试题及答案解析
- 2026广东水利电力职业技术学院招聘25人模拟笔试试题及答案解析
- 2025山东德州临邑县人民医院招聘备案制工作人员15人备考笔试试题及答案解析
- 安全在我行课件
- 2025福建厦门市集美区幸福幼儿园招聘2人备考考试试题及答案解析
- 2026江苏徐州医科大学附属医院招聘53人(卫生技术类普通岗位)考试备考题库及答案解析
- 2025财达证券股份有限公司财富管理与机构业务委员会山东分公司招聘1人考试备考题库及答案解析
- 2026中国农业科学院第一批统一招聘14人(蔬菜花卉研究所)备考考试试题及答案解析
- 2025德州夏津县事业单位工作人员“归雁兴乡”参考考试题库及答案解析
- 一级建造师考试机电工程管理与实务试卷及答案(2025年)
- 2026年潍坊护理职业学院单招职业倾向性考试必刷测试卷及答案1套
- 医保政策学习课件
- 雨课堂学堂在线学堂云《科学研究方法与论文写作(复大)》单元测试考核答案
- 2025浙江省自由贸易发展中心招聘工作人员5人(第二批)参考笔试试题及答案解析
- 光学加工机械项目可行性分析报告范文
- 网易丁磊成功创业之路
- 老公情人签约协议书
- 学堂在线雨课堂《唐宋名家词(河南大学)》网课学堂云单元测试考核答案
- 煤矿班组长安全培训
- 体育培训校区管理制度
评论
0/150
提交评论