习题4
1.0; 2.9;
3.20 #include { int a,b,x,y; scanf(\ if(a<=b) { x=1; printf(\ else {y=2; printf(\ } } 7. #include { int ch1,ch2; ch1=getchar(); ch2=getchar(); if((ch1-ch2)/2==0) { putchar(ch1+1); putchar('\\n'); putchar(ch2+2); putchar('\\n'); } else { putchar(ch1-1); putchar('\\n'); putchar(ch2-1); putchar('\\n'); } } 8. #include { int a,b; scanf(\ if(a%b==0) printf(\ else printf(\??%d\\n\} 9. #include { float x,y,l; scanf(\ l=sqrt((x-2)*(x-2)+(y-2)*(y-2)); if(l>1) printf(\点A在圆外\\n\ else if(l=1) printf(\点A在圆上\\n\ else printf(\点A在圆内\\n\} 12.不嵌套的if语句 #include { int x,y; scanf(\ if(x<8) if(x>0) y=x+1; else if(x==0) y=0; else if(x>-5) y=x-1; printf(\} 嵌套的if语句: #include { int x,y; scanf(\ if(x<=0) if(x==0) y=0; } else if(x>-5) y=x-1; else if(x<8) y=x+1; printf(\ 习题5 1. #include { int n,x=0,sum=0,i=-1; float average; scanf(\ while(x<=n) { sum+=x; x+=2; i++; } average=sum/i; printf(\} 2. #include { char ch; int let = 0; int num = 0; while ((ch = getchar()) != '*') //输入*结束 { if ((ch >= 'A' && ch <= 'Z') || (ch >= 'a' && ch <= 'z')) //如果是字母,let++ { let++; } else if (ch >= '0' && ch <= '9') //如果是数字,num++ { num++; } } printf(\字母:%d\\n\ //打印字母数 printf(\数字:%d\\n\ //打印数字数 return 0;} }(来源:百度账号terranlong) 3. #include { int n,i,a,sum=0,m; scanf(\ m=n; for(i=1;(m/i)!=0;) { a=n; sum+=a; n=(n-a)/10; i*=10; } printf(\} 4. #include #include { float sum=200; int n=0; while(sum<500) { sum*=1.045; n++; } printf(\} 6. #include void main() { int x=0,y; int shuzi(int n); for(n=1;n<=999;n++) { while(n%3==0) { y=shuzi(n); if(y!=0) { x++; printf(\ break; } break; }