资源描述:
《C程序设计教程与实验_实验五答案》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、C程序设计教程实验五吉顺如Sy5_1:#includemain(){inti,sum=0;i=1;while(i<=100){sum=sum+i;i++;}printf("Thesumfrom1to100is%d",sum);}Sy5_2:#includemain(){charx;x='z';while(x>='a'){printf("%c",x);x--;}}Sy5_3:#includemain(){inti,j,k;charch;scanf("%c",&ch);k=ch-'A'+1;
2、for(i=1;i<=k;i++){for(j=20;j>=i;j--)printf("%c",'');for(j=1;j<=2*i-1;j++)printf("%c",'A'+i-1);printf("");}k=ch-'A';for(i=k;i>=1;i--)for(j=20;j>=i;j--)printf("%c",'');for(j=1;j<=2*i-1;j++)printf("%c",'A'+i-1);printf("");}}Sy5_4:#includemain(){intr,m,n,k,t;scanf("%
3、d%d",&m,&n);if(mmain(){intday,x1,x2;day=0;x1=1020;while(x1!=0){x2=x1-x1/2-2;x1=x2;day++;}printf("day=%d",day);}Sy5_6:#includemain(){inti,j;for(i=0;i<10;i++){j=i*10+6
4、;if(j%3!=0)continue;printf("%d",j);}}Sy5_7:#includemain(){inti=0,j=0,k,sum=0;while(i<10){j=i*10+8;k=80+i;sum=sum+j+k;i++;}printf("sum=%d",sum-88);}Sy5_8:#includemain(){inti=1;longn=1;floats=0,t=1;while(t>=1e-5){n=n*i;t=(float)1/n;s=s+t;i++;}printf("s=%f"
5、,s+1);}Sy5_9:#includemain(){inti;for(i=900;i<=1000;i++)if(i%5==2&&i%7==3&&i%3==1)printf("%d",i);}Sy5_10:#includemain(){inti,j,m,n;floatsum,ave,score;printf("请输入学生数和课程数:");scanf("%d%d",&m,&n);for(i=1;i<=n;i++){sum=0;for(j=1;j<=m;j++){printf("请输入学生成绩:");
6、scanf("%f",&score);sum=sum+score;}ave=sum/m;printf("%d%f%f",i,sum,ave);}}