1)三位逆序
1 #include2 3 int main() 4 { int orig = 0; 5 int bai = 0; 6 int shi = 0; 7 int ge =0; 8 9 printf("请输入三位数\n");10 scanf("%d", &orig);11 ge = orig % 10;12 shi = orig / 10 % 10;13 bai = orig / 100;14 15 printf("所得逆序为%d\n", ge*100 + shi*10 + bai);16 return 0;17 }
#includeint main(){ int hour1 = 0; int minute1 = 0; int BJT = 0; printf("请输入时间(北京时间)格式如2307(0-2359之间)\n"); scanf("%d", &BJT); if ( 0< BJT < 2359){ hour1 = BJT / 100; minute1 = BJT % 100; if ( hour1 > 7 ){ printf("协调时为今日%d", (hour1 - 8)*100 + minute1); }else{ printf("协调时为前一日%d", (hour1 + (24-8))*100 + minute1); }//利用了补码来计算跨日时间 }else{ printf("输入格式有误,请重新输入\n"); } return 0;}
switch( expression ) {
case A: statement list; break; case B: statement list; break; ... case N: statement list; break; default: statement list; break; }1 #include2 3 int main() 4 { int orig; 5 int readability; 6 int strenth; 7 8 printf("请输入RS数据([11,59]之间)\n"); 9 scanf("%d", &orig);10 11 readability = orig / 10;12 strenth = orig % 10;13 14 switch( readability ){15 case 1 : printf("Unreadable,");break;16 case 2 : printf("Barely readable, occasional words distinguishable,");break;17 case 3 : printf("Readable with considerable difficulty,");break;18 case 4 : printf("Readable with practically no difficulty,");break;19 case 5 : printf("Perfectly readable,");break;20 }21 switch( strenth ){22 case 1 : printf("faint signals, barely perceptible");break;23 case 2 : printf("very weak signals");break;24 case 3 : printf("weak signals");break;25 case 4 : printf("fair signals");break;26 case 5 : printf("fairly good signals");break;27 case 6 : printf("good signals");break;28 case 7 : printf("moderately strong signals");break;29 case 8 : printf("strong signals");break;30 case 9 : printf("extremely strong signals");break;31 }32 33 return 0;34 35 }
4)奇偶个数
#includeint main(){ int even = 0; int odd = 0; int x; scanf("%d", &x); while( x != -1 ){ if( x%2 == 0 ) even++; else odd++; scanf("%d", &x); } if( x == -1 ){ printf("%d %d", even, add); } return 0;}