资源描述:
《高级语言程序设计课后习题答案-宁爱军版》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、西南交通大学通信工程系高级语言程序设计课后习题编程题答案(部分)第六章:循环结构程序设计6.3.#includeintmain(){inta=l,b=2,n;doublesum=0;for(n二0;n<=20;n++){sum=sum+(double(b/a));b=a+b;a=b;}printf(〃%lf〃,sum);return0;}6.5・#includeintmainO{doubles=0,a=l,t;intn二1;do{t=l/a;s二s+t;a二a+n;n++;}while(t>=0.000001);printf(〃%
2、lf〃,s);return0;()UEIPOA〈q・.2P4S〉①pnoussLLIIn①.1-JLJ5、、)七u=d-(10000oHoouqM亠-4+ulnsnulnsWE二*"二.'■①snop二uwns=①Iqnopou-sul4U_〈q・.2p4s〉opnlous〈q・.2p4s〉a>pnl二uruxpr)七upd亠亠二+E(Osxu/I}(++二U〉I二丄).IOJO匕(丰USOOI〉UOJHU)JOJ匚匸C4U卄voidmain(){doublesum=0,x=0,n=0,av=0;printfC请输入成绩:〃);do{sum二sum+x;scanf&
3、x);n++;}while(x!=-99);av=sum/(nT);printfC平均成绩为%lf〃,av);}6.17・#includevoidmain(){intm,n,i,sum=0;printf(z,请输入整数m和n:〃);scanf(〃%d%d〃,&m,&n);for(i=2;i<=m;i++){if(m%i==0&&n%i==0)sum+=i;}printf(,zm和n的公约数之和为%d〃,sum);}6.18・#includevoidmain(){intman,woman,child;for(man=0;ma
4、n<=9;man++)for(woman=0;woman<=12;woman++){chi1d二2*(36-4*man-3*woman);if(child>=0&&man+woman+chiId二二36)printf(〃m8n:%dwom8n:%dchild:%drr,man,woman,child);6.20.#includevoidmain()ints;for(s=0;;s++){if((s%2二二1)&&(s%3=2)&&(s%5二二4)&&(s%6二二5)&&(s%7二二0))break;}printf(〃阶梯总共有:%d〃,s)
5、;}第七章:数组7.2#include#includenclude〈time・h>voidmain(){inta[100],sum=0;inti,n=0;doubleav;srand(time(0));for(i=0;i<=99;i++)a[i]=rand()%200;printf(zz数组为:〃);for(i=0;i<=99;i++)printf(〃%4d〃,a[i]);for(i=0;i〈二99;i++){if(a[i]%2==0){sum=sum+a[i];n++;av=((double)sum)/n;printfC值为偶
6、数的元素个数为:%d〃,n);printf(,z值为偶数的元素平均值为:%lf〃,av);7.6#includcvoidmain(){inta[100];inti,j=0;for(i=l;i<=500;i++)if((i%7==0)
7、
8、(i%ll二二0))if(!(i%7==0&&i%ll==0)){a[j]二i;j++;}for(i=0;i<=j-l;i++)printf("%4d〃,a[i]);}7.10#include#include#includevoidmain(){inta[
9、100];inti,x;srand(time(0));for(i=0;i<=99;i++)a[i]=rand()%100;printf(zz数组为:〃);for(i=0;i<=99;i++)printf(〃%3d〃,a[i]);printf(〃〃);printfC从键盘输入x:〃);scanf("%cT,&x);for(i=0;i<=99;i++)if(a[i]二二x)a[i]-0;printf(〃删除与x值相等的元素之后的数组为:〃);for(i=0;i<=99;i++)printf(〃%3d〃,a[i]);printf("〃);7.13/*定义输入(