{ t = x; x = z; z= t; } if( y > z )
{ t = y; y= z; z = t; }
printf(“%d %d %d\\n”, x, y ,z); } (2)
#include
int score;
scanf(“%d”, &score);
if ( score < 0 || score > 100 ) printf(“成绩不合理\\n”); else if( score>=90 ) printf(“优秀\\n”); else if( score>=80 ) printf(“良好\\n”); else if( score >= 70 ) printf(“中等\\n”); else if( score >= 60 ) printf(“及格\\n”); else printf(“不及格\\n”); } (3)
#include
int n;
int g,s,b,q;//各位上的数值 scanf(“%d”, &n); g = n; //个位 s = n/10; //十位 b = n/100; //百位 q = n/1000; //千位 if( n < 10 ) //一位数 { printf(“%d\\n”, 1);//位数 printf(“%d\\n”, g); //各位上的数值 }
else if ( n < 100 ) //两位数 { printf(“%d\\n”, 2);//位数 printf(“%d %d\\n”, g,s);
}
else if ( n < 1000 ) //三位数 { printf(“%d\\n”, 3);//位数 printf(“%d %d %d\\n”, g, s, b); }
else if ( n < 10000 ) //四位数 { printf(“%d\\n”, 4);//位数 printf(“%d %d %d %d\\n”, g, s, b, q); } } (4)
#include
int n;
scanf(“%d”, &n);
if( n % 3==0 && n%5==0 && n%7==0 ) printf(“能同时被3、5、7整除\\n”); else if( n%3==0 && n%5==0) printf(“能被3和5整除\\n”); else if( n%3==0 && n%7==0 ) printf(“能被3和7整除\\n”); else if( n%5==0 && n%7==0 ) printf(“能被5和7整除\\n”);
else if( n%3==0 || n%5==0 || n%7==0 ) { if( n%3==0 ) printf(“能被3整除\\n”); else if( n%5==0 ) printf(“能被5整除\\n”); else printf(“能被7整除\\n”); } else printf(“不能被3、5、7中任一个数整除\\n”); } (5)
#include
int carType;//车型。1代表夏利;2代表富康;3代表桑塔纳 double xiali = 2.1; //每公里价格
double fukang = 2.4; double sangtana = 2.7; double distance; //距离
double totalMoney;//总的收费
printf(\请输入您乘坐的车型:1代表夏利;2代表富康;3代表桑塔纳:\
scanf(\
printf(\请输入您乘车的总路程:\ scanf(\ if( carType == 1)//夏利 { if( distance < 3 ) totalMoney = 7.0; else totalMoney = 7 + xiali * (distance – 3); }
else if( carType == 2 ) //富康 { if( distance < 3 ) totalMoney = 8.0; else totalMoney = 8 + fukang * (distance – 3); }
else if( carType == 3 ) //富康 { if( distance < 3 ) totalMoney = 9.0; else totalMoney = 9 + sangtana * (distance – 3); }
printf(\(四舍五入)您的车费为:%.0lf\\n\
} (6)
#include
double a, b, c;
scanf(“%lf%lf%lf”, &a, &b, &c); if( a+b>c && b+c>a && c+a>b ) { if( a==b && b==c ) printf(“等边三角形\\n”); else if( a==b || b== c || c==a ) printf(“等腰三角形\\n”);
else printf(“一般三角形\\n”); } else printf(“不能构成三角形\\n”); }
第5章
1. (1)C(2)C(3)K=36(4)C(5)B 2.
(1) 3次
(2) x>=1 && x<=10 || x>=200&&x<210 (3) e == 0 (4) 6次 (5) 10 3.
(1) 20,10 (2) 16,0
(3) 7BAB4BAB1BC (4) ABABABC (5) ******
****** ****** ****** 4.
(1) a != b (2) n / 10
(3) scanf(“%d”, &a);
5. (3) 行 int fac = 1, sum = 0; 6. (1)
#include
char ch;
int alpha=0, space=0, digit=0, other=0; while( (ch=getchar( ) ) != ?\\n? ) { if( ch>=?A?&&ch<=?Z? || ch>=?a?&&ch<=?z?) alpha++; else if( ch>=?0? && ch<=?9?) digit++; else if( ? ? == ch ) space++; else other++; }
printf(“%d %d %d %d\\n”, alpha, digit, space, other ); } (2)
#include
int m20, m10;
for(m20=1; m20<5; m20++) { for(m10 = 1; m10<10; m10++) if( 20*m20+10*m10 == 100 ) printf(“%d, %d\\n”, m20, m10 ); } } (3)
#include
int x, y, z;
for(x=0; x<10; x++) for(y=0; y<10; y++) for(z=0; z<10; z++) if( x*100+y*10+z + y*100+z*10+z == 532 ) printf(“%d %d %d\\n”, x, y, z); } (4)
#include
int row, spaceCount,starCount; int n;
scanf(\