资源描述:
《标准C语言程序设计及应用周纯杰每章课后编程题.doc》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、P71#include#includevoidmain(){clrscr();inti;intsum;sum=0;printf("Enteri:");scanf("%d",&i);while(i<=100){sum=sum+i;i++;}printf("sum=%d",sum);getch();}P96(6)#include#includevoidmain(){inta,b,sum,i;a=8;b=1;sum=8;for(i=1;i<=9;i++);{b=b
2、+3;a=a+b;sum+=a;}printf("sum=%d",sum);getch();}P97(18)#include#includevoidmain(){floatx,a,b,expx;while(1){chari;a=1;expx=1;b=1;printf("pleaseinputx:");scanf("%f",&x);if(x<1e-6){break;}for(i=1;;i++){a*=x;b*=i;expx+=a/b;if(a/b<1e-6){break;}else{contin
3、ue;}}printf("expx=%f",expx);getch();clrscr();}}P90#include#includevoidmain(){unsignedlonginta,i;for(a=10;a<=100;a++){for(i=2;i=a){printf("%dt",a);}}getch();}P97(9)#include#include#includevo
4、idmain(){unsignedinta,b,i;randomize();a=random(65535);for(i=1;i<=20;i++){printf("Pleaseguessa(0~65535):");scanf("%d",&b);if(a==b&&i==1){printf("Right!Youhaveguessed1time.");printf("Enteranysingelnumbertobreak.");scanf("%d",&b);if(1){break;}}elseif(a==b&&i>1){printf
5、("Right!Youhaveguessed%dtimes.",i);printf("Enteranysingelnumbertobreak.");scanf("%d",&b);if(1){break;}}elseif(a>b){printf("Wrong!Yournumberissmall.");continue;}else{printf("Wrong!Yournumberislarge.");continue;}}}P97(19)#include#include#include
6、voidmain(){floatx,a;chari;x=1.0;printf("Pleaseinputa(jisuanadepingfanggen):");scanf("%f",&a);for(i=1;;i++){if(fabs(x-(x+a/x)/2)<1e-5){x=(x+a/x)/2;break;}else{x=(x+a/x)/2;}}printf("x=%f",x);getch();clrscr();}P97(16)#include#includevoidmain(){
7、longintx,S;inta,n,i;printf("Pleaseinputa,n:");scanf("%d,%d",&a,&n);S=0;x=0;for(i=1;i<=n;i++){x=x*10+a;S=S+x;}printf("S=%ld",S);getch();}P97(11)#include#includevoidmain(){inti;inta,b;printf("Pleaseinputa,b:");scanf("%d,%d",&a,&b);for(i=a0;i-
8、-){if(a%i==0&&b%i==0){printf("Themaxis%d.",i);break;}}for(i=a>b?a:b;;i++){if(i%a==0&&i%b==0){printf("Theminis%d."