1 / 9

改 错

改 错. 1 、取 {2m, 3n |m≥1 , n≥1} 中由小到大排列的前 70 项数。 #include<stdio.h> void main( ) {double m,n; int k; /**********error************/ m=2, n=3; for(k=0;k<70;k++) /**********error************/ if(n<m) {printf("%40.0f",m); m*=2; } else {printf("%40.0f",n);

lark
Download Presentation

改 错

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 改 错

  2. 1、取{2m, 3n |m≥1,n≥1}中由小到大排列的前70项数。 #include<stdio.h> void main( ) {double m,n; int k; /**********error************/ m=2, n=3; for(k=0;k<70;k++) /**********error************/ if(n<m) {printf("%40.0f",m); m*=2; } else {printf("%40.0f",n); n*=3; } return; } m=2;n=3; if(m<n)

  3. 2、求 1- 1/2+1/3-1/4+…+ 1/99-1/100 的值。 #include<stdio.h> void main() {int i,t; float s=0; for (i=t=1;i<=100;i++) { /***********error*************/ s+=t/i; t=-t; } /***********error************/ printf("s=%d\n",s); } s+=(float)t/i; printf("s=%f\n",s);

  4. 3、任意输入一串字符,以“?”结束,分别统计其中字母、数字和其他字符的个数。3、任意输入一串字符,以“?”结束,分别统计其中字母、数字和其他字符的个数。 #include<stdio.h> void main() {char c; int n1=0,n2=0,n3=0; /***********error************/ for((c=getchar())!='?') /***********error************/ if((c>='A'&&c<='Z')&&(c>='a'&&c<='z'))n1++; else if(c>='0'&&c<='9')n2++; else n3++; printf("%d,%d,%d\n",n1,n2,n3); } for(;(c=getchar())!='?';) if((c>='A'&&c<='Z')||(c>='a'&&c<='z'))n1++;

  5. 7、程序的功能是把两个字符串连接起来,请改正程序中的错误。7、程序的功能是把两个字符串连接起来,请改正程序中的错误。 #include<stdio.h> void main() { char s1[100],s2[40]; int i=0,j=0; printf("\n please input string1\n"); scanf("%s",s1); printf(" please input string2\n"); scanf("%s",s2); while(s1[i]!='\0') i++; /***********error************/ while(s2[j]='\0') s1[i++]=s2[j++]; /***********error************/ s1[i]="\0"; printf("linked string:%s",s1); } le(s2[jwhi]!='\0') s1[i]='\0';

  6. 8、程序的功能是判断输入的字符串是否是“回文”,若是“回文”,输出“yes”,否则输出“no”。,请改错:8、程序的功能是判断输入的字符串是否是“回文”,若是“回文”,输出“yes”,否则输出“no”。,请改错: void main() {char s[81],cr,*pi,*pj; int n; gets(s); n=strlen(s); pi=s;pj=s+n-1; while(*pi==' ') pi++; while(*pj==' ') pj--; while((pi<pj)&&(*pi==*pj)) {pi++;pj--;} /***********error************/ if(pi!=pj) printf("NO\n"); else printf("YES\n");} if(pi<pj) printf("NO\n");

More Related