C++编程课后答案之数组.doc

上传人:laozhun 文档编号:2384483 上传时间:2023-02-17 格式:DOC 页数:25 大小:259.50KB
返回 下载 相关 举报
C++编程课后答案之数组.doc_第1页
第1页 / 共25页
C++编程课后答案之数组.doc_第2页
第2页 / 共25页
C++编程课后答案之数组.doc_第3页
第3页 / 共25页
C++编程课后答案之数组.doc_第4页
第4页 / 共25页
C++编程课后答案之数组.doc_第5页
第5页 / 共25页
点击查看更多>>
资源描述

《C++编程课后答案之数组.doc》由会员分享,可在线阅读,更多相关《C++编程课后答案之数组.doc(25页珍藏版)》请在三一办公上搜索。

1、循环结构的程序设计实验目的:掌握数组的应用1#includevoid main ()int i,a20,w,n,m,t;coutn;cout输入数据:;for(i=0;iai;w=0;m=0;for(i=0;iaw)w=i;else if(aiam)m=i;t=am;am=a0;a0=t;t=aw;aw=an-1;an-1=t;cout处理结果:;for(i=0;in;i+)cout ai;coutendl;2#includevoid main()int i=-1,m=0;float a20,ave,sum=0;printf(输入实数); do i+;scanf(%f,&ai);while(a

2、i0);for(i=0;ai0;i+)sum=sum+ai;ave=sum/(i+1);for(i=0;ai0;i+)if(aiave)m=m+1;printf(大于等于平均值的实数个数);printf(%dn,m);3#includevoid main ()int i,a100,k=1,m=1;for(i=1;i=100;i+)if(i%7=0)|(i%11=0)ak=i;k+;m+;cout1100之间能被7或11整除的所有整数:endl;for(k=1;k=m;k+)cout ak;if(k%10=0)coutendl;coutendl;4#includevoid main()int i

3、=0,n=0,a20,m;coutai;i+;n+;while(ai-1!=0);coutm;for(i=0;in;i+)if(ai=m)break; if(in-1) coutm在数列中,是第i+1个数。;elsecoutm不在数列中。;coutendl;5#includevoid main()int a20,i=0,n,k,j;coutai;n=i;while(ai0);coutk;for(i=1;ai0;i+)if(k=ai)j=i;for(j=i;jn;j+)aj=aj+1; if(k=ai)如果是3个一难道要继续重复吗 j=i;for(j=i;j0;i+)coutai ;6#incl

4、udevoid main()int i,a20,n;coutn;cout请输入数据:;for(i=1;iai;a0=an;for(i=n-1;i0;i-)ai+1=ai;a1=a0;for(i=1;i=n;i+)cout ai;coutendl;7#includevoid main()int a11,i,j,w,t,k;cout输入数列:;for(i=1;iai;for(i=1;i10;i+)w=i;for(j=i+1;j=10;j+)if(awaj)w=j;if(w!=i)t=aw;aw=ai;ai=t;coutendlk;for(i=1;ik) ai-1=ai;else ai-1=k;br

5、eak;coutendl处理结果:;for(i=0;i=10;i+)coutai ;coutendl;8#includevoid main ()int a20,i=-1,n,sum=0 ,w ,j,t,r=0,k; coutai;n=i; while(ai0);for(i=0;i=n-2;i+)w=i;for(j=i+1;j=n-1;j+)if(awaj)w=j;if(w!=i)t=aw;aw=ai;ai=t; cout素数:;for(i=0;in;i+) r=0;for(k=1;k=ai;k+)if(ai%k=0)r=r+1; if (r=2)sum=sum+ai;cout ai;coute

6、ndlsum=sumendl;9#includevoid main()int i,a10,k,j,n,t,w;/k是整数,k是k/10,n是计算个数,t是中间变量coutk;for(i=0;k0;i+)ai=k%10;k=k/10;n=i+1;for(i=0;in-1;i+)w=i;for(j=i;jn;j+)if(awaj)w=j;if(i!=w)t=aw;aw=aj;aj=t;cout结果:;for(i=0;in;i+)coutai;coutendl;10#includevoid main()int a23,b23,c23,i=0,j=0;cout输入第一个矩阵:endl;for(i=0;

7、i2;i+)coutendl;for(j=0;jaij;cout输入第二个矩阵:endl;for(i=0;i2;i+)coutendl;for(j=0;jbij;for(i=0;i2;i+)for(j=0;j3;j+)cij=aij+bij;cout矩阵和:endl;for(i=0;i2;i+)coutendl;for(j=0;j3;j+)coutcij ;11#includevoid main ()int a33,i,j;for(i=0;i3;i+)for(j=0;jaij;cout其转置为:endl;for(j=0;j3;j+)coutendl;for(i=0;i3;i+)coutaij

8、;coutendl其上三角部分:endl;for(i=0;i3;i+)coutendl;for(j=0;j3;j+)if(ji)cout ;elsecoutaij ;coutendl其下三角部分:endl;for(i=0;i3;i+)coutendl;for(j=0;j=i;j+)coutaij ;coutendl; 12#includevoid main()Rol he row 的位置放的地方int a34,i,j,max,min,row,col;cout输入矩阵:endl;for(i=0;i3;i+)for(j=0;jaij;for(i=0;i3;i+) max=ai0; col=0;fo

9、r(j=1;jmax)max=aij;col=j;cout第i+1行最大数:max、在第(col+1)列:endl;for(j=0;j4;j+) row=0;min=a0j;for(i=1;i3;i+)if(aijmin)min=aij;row=i;cout第j+1列最小数:min、在第(row+1)行:endl;coutendl;13#includevoid main ()int a34,j,i;cout输入矩阵:endl;for(i=0;i3;i+)for(j=0;jaij;cout转置:endl;for(j=0;j4;j+)coutendl;for(i=0;i3;i+)coutaij ;

10、15#includevoid main()char a20 ;int m,k,i;printf(输入字符串:);gets(a);for(i=0;i10;i+) m=0;for(k=0;ak!=0;k+)if(ak=i+48)m=m+1;printf(字符%d的个数:%d,i,m); printf(n);printf(n);16#includevoid main ()char a10,t;int i,j,l,w;couta;l=0;while(al!=0)l+;for(i=0;il;i+)w=i;for(j=i+1;jl+1;j+)if(awaj)t=aj;aj=aw;aw=t;cout结果:;

11、for(i=0;i=l;i+)coutai;coutendl;17#include#includevoid main()char a20,t;int n,i=0,w,j,m;puts(输入字符串:);gets(a);n=strlen(a);for(i=0;in-1;i+)w=i;for(j=i+1;jaj)w=j;if(w!=i)t=aw;aw=ai;ai=t;puts(结果);for(i=0;in;i+)m=ai;if(m%3)!=0)printf(%c,ai);printf(n);18#include#includevoid main ()char a20,b20,c20,d20;int

12、i,n,j=0;printf(输入字符串1:);gets(a); printf(输入字符串2:);gets(b);printf(输入插入的位置:);scanf(%d,&n);for(i=0;in;i+)ci=ai;ci=0;/puts(c);for(i=n;ai!=0;i+)dj+=ai;dj=0;strcat(c,b);strcat(c,d);puts(c);19#includefloat ave (int a5,int );void main()int a55,i,j;float m;cout输入数据:endl;for(i=0;i5;i+)for(j=0;jaij; m=ave(a,25)

13、;cout所有元素平均值:mendl;float ave(int a5,int)int i ,j;float sum=0.0;for(i=0;i5;i+)for(j=0;j5;j+)sum=sum+aij;return (sum/25.0 );20#includevoid main()char t30,c;int i,l,e,b;printf(请输入字符串:);gets(t);l=0;while(tl!=0)l+;b=0;e=l-1;while(be)c=tb;tb=te;te=c;b+;e-;printf(首尾互换后的字符串:);puts(t);21#include#includevoid

14、main()char a20,b20;int i,m,n;printf(输入字符串:n);gets(a);m=strlen(a);for(i=0;i9;i+)gets(b);n=strlen(b);if(mn)strcpy(a,b);m=strlen(a);puts(a);22#includevoid transpose(int a,int n);void main ()int a10,i=-1,n;coutai;n=i;while(ai0);transpose(a,n);cout转换后的数列:;for(i=0;in;i+)coutai ;coutendl;void transpose(int

15、 a,int n) int t,i=-1;while (in)t=ai;ai=an;an=t;i+;n-;23#include#includeint m=0,n=0;int tj( char a)int i,k=0;for(i=0;ai!=0;i+)if(ai=32)k=k+1;else if(ai=48&ai=a&ai=A&ai=Z)m=m+1;return k;void main()int k,q,l;char a20;printf(输入字符串:);gets(a);k=tj(a);q=strlen(a);l=q-m-n-k;printf(结果:n);printf(英文字母:%dn数字字符:

16、%dn空格:%dn其他:%dn,m,n,k,l);以下是大学体验英语综合教程2(第三版)课后翻译答案Unit11. 任何年满18岁的人都有资格投票。(be eligible to, vote)Answer:Anyone over the age of 18 is eligible to vote.2. 每学期开学前,这些奖学金的申请表格就会由学校发给每一个学生。(apply for, scholarship)Answer:A form to apply for these scholarships is sent by the university to every student befor

17、e the start of every semester.3. 遵照医生的建议,我决定戒烟。(on the advice of)Answer:On the advice of my doctor, I decided to give up smoking.4. 公园位于县城的正中央。(be located in)Answer:The park is located right in the center of town.5. 这所大学提供了我们所需的所有材料和设备。(facilities)Answer:The university provides all the materials and

18、 facilities we desire.1. 他们花了多年的时间寻找内心的平静,但是收效甚微。(search for)Answer:They spent many years searching for peace of mind, but with little success.2. 这种新药的成功研制已经使许多疾病的治疗发生了根本性的变革。(revolutionize)Answer:The successful development of the new drug has revolutionized the treatment of many diseases.3. 由于这个国家的

19、经济不景气,这家公司濒于破产。(on the edge of)Answer:The company is on the edge of bankruptcy due to the economic depression in the country.4. 大学毕业后他成为了一名护士。他认为护士这一职业可能很有发展前途。(rewarding)Answer:He became a nurse after college. He thought nursing could be a very rewarding career.5. 他像往常一样在文件上签了名。(just as)Answer:He s

20、igned his name on the paper just as he has always done it.Unit21. 警察们正忙着填写关于这场事故的各种表格。(fill out)Answer:The policemen are busy fi lling out forms about the accident.2. 我想在还车之前把油箱加满。(fill up, fuel tank)Answer:I want to fi ll up the fuel tank before returning the car.3. 如果你要投诉,最好遵循正确的程序。(follow the pro

21、cedure)Answer:If you want to make a complaint, youd better follow the correct procedure.4. 要不是约翰帮忙,我们绝不会这么快就完成实验。(without)Answer:We couldnt have fi nished the experiment so soon without Johns help.5. 暴风雨之后,岸边的人们焦急地搜索湖面以期发现小船的踪迹。(scan for)Answer:After the storm, the people on the shore anxiously scan

22、ned the lake for any sign of the boat.1. 这个国家不大,但是在国际事务中它却发挥着重要作用。(play a role)Answer:This country is not big, but it plays an important role in international affairs.2. 正是在我叔叔的帮助下,我得以克服困难,按时完成了任务。(it is . that)Answer:It was with the help of my uncle that I overcame the difficulty and completed the

23、assignment in time.3. 毕业时他决定留在北京,而他最好的朋友却选择了去西藏。(while)Answer:While he decided to stay in Beijing upon graduation, his best friend chose to go to Tibet.4. 在这次校园英语演讲比赛中,我们班的玛丽获得了第三名。(come in)Answer:In this Campus English Speaking Contest, Mary from our class came in third.5. 你应该知道学习弹钢琴需要有时间,有金钱,还要有毅力

24、。(as well as)Answer:You should know that it takes time, money as well as perseverance to learn to play the piano.Unit31. 我发现量入为出地过日子越来越难了。(increasingly)Answer:I find it increasingly difficult to live within my income.2. 现代政治家们都试图以电视讲话来影响普通百姓。(reach out)Answer:Modern politicians try to reach out to o

25、rdinary people in their TV speeches.3. 应该帮助学生对人生采取积极的态度。(adopt)Answer:Pupils should be helped to adopt a positive attitude to life.4. 希望全班同学参加这些讨论。(participate in)Answer:Everyone in the class is expected to participate in these discussions.5. 如果你犯了罪就必须受到惩罚。(crime)Answer:If you commit a crime you mus

26、t expect to be punished.1.儿子的死让老妇人变得麻木痴呆了。(numb)Answer:The old woman was numbed by her sons death.2.身处所有这些烦恼之中,他依然能保持乐观。(in the midst)Answer:In the midst of all troubles, he managed to remain cheerful.3. 虽有困难,他们还是设法坚持试验下去。(carry on)Answer:They managed to carry on their experiments in spite of the di

27、fficulties.4.我们必须淘汰不合格的申请人。(weed out)Answer:We have to weed out unqualified applicants.5. 医生要他减少抽烟。(cut down on)Answer:The doctor told him to cut down on smoking.Unit41.她在公共汽车站一直等到末班车进站。(come in)Answer:She waited at the bus stop until the last bus came in.2.如果我们能帮得上忙,尽管和我们联系。(contact)Answer:If there

28、 is any way we can be of assistance, please do not hesitate to contact us.3 .他需要多少船务人员才能使他的游艇航行?(crew, yacht)Answer:How many crew does he need to sail his yacht?4 .虽然她的新书没有上一本好,但是我还是喜欢它。(not quite as)Answer:I enjoyed her new book though its not quite as good as her last one.5 .我从未遇到过如此善良的人。(never be

29、fore)Answer:Never before have I met such a kind person.1.公共汽车放慢速度并停下,让那位乘客上车。(slow down)Answer:The bus slowed down and stopped to allow the passenger to get on board.2.许多车子都驶过去了,可是没有一辆愿意让我们搭便车。(roll by)Answer:Many vehicles rolled by, but no one offered us a ride.3 .请勿践踏草地。(get off)Answer:Please get

30、off the grass.4.他按妻子的吩咐,一下班就去了市场。(make ones way)Answer:He made his way to the marketplace right after work, as his wife had asked him to do.5 .值得庆幸的是,史蒂夫 (Steve) 从自行车上摔下来时没有摔断骨头。(luckily)Answer:Luckily, Steve didnt break any bones when he fell off his bike.Unit51. 我们得把感情放在一边,从专业的角度来对待这件事。(from a pro

31、fessional standpoint)Answer:We have to put aside our emotions and take it from a professional standpoint.2. 这部戏非常精彩,我很快就沉浸于激动人心的剧情之中。(lose oneself in)Answer:The play was so wonderful that I soon lost myself in the excitement of it.3 .她没有什么爱好除非你把看电视也算是一种爱好。(unless)Answer:She hasnt got any hobbies unl

32、ess you call watching TV a hobby.4. 他说他是直接从市长本人那里得到这个信息的。(first-hand)Answer:He said that he had got the information first-hand from the Mayor himself.5 .既然你不能回答这个问题,我们最好问问别人。(since)Answer:Since you cant answer the question, perhaps wed better ask someone else.1. 由于公共汽车司机突然刹车,旅客们都不由自主地向前摔倒。(brake, pi

33、tch forward)Answer:All the passengers pitched forward because the bus driver braked sharply.2. 这个协议将冲破对自由贸易设置的障碍。(break through, obstacle)Answer:This agreement will break through the obstacles to free trade.3 .我刚放下叫出租车的电话,车就来了。(soon after)Answer:The taxi arrived soon after I rang for it.4. 在过去,不管我什么

34、时候到家,我父母总会等我。(no matter)Answer:My parents always waited up for me no matter what time I got home.5 .由于没有一方愿意让步,两个公司之间的对话完全破裂了。(break down)Answer:Talks between the two companies completely broke down, because neither of them wanted to give in.Unit61. 那件工作很难做,不过我想试试看。(have a shot)Answer:Its a difficul

35、t job, but Id like to have a shot.2. 这是一本关于商务实践而非理论的书。(as opposed to)Answer:This is a book about business practice as opposed to theory.3. 社会活动从未耽误她的学习。(in the way)Answer:Social activities never get in the way of her studies.4. 直到1911年人们才发现第一种维生素。(It is not until . that)Answer:It was not until 1911 that the first of the vitamins was identified.5. 尽管年事已高,爷爷每天还帮忙做家务。(despite)Answer:Despite advanced years, Grandpa helps do housework every day.1. 我们的婚姻很幸福,但我们也曾经历过许多坎坷。(ups and downs)Answer:Our marriage is happy but weve had many ups a

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 建筑/施工/环境 > 项目建议


备案号:宁ICP备20000045号-2

经营许可证:宁B2-20210002

宁公网安备 64010402000987号