if(number%3==0){ printf("Tiger\n"); }
else if(number%3==1){ printf("Dog\n"); }
else if(number%3==2){ printf("Cat\n"); }
return 0; }
10.(也可以参考5.3节用if-else if -else 条件分支语句解决此问题) #include <stdio.h> int main() {
int number; double cost;
printf("输入用水量(正整数):"); scanf("%d",&number); switch(number){ case 1: case 2: case 3: case 4: case 5: cost=number*2.3; break; case 6: case 7: case 8: case 9: case 10: case 11: case 12: cost=number*5; break; default:
cost=number*6; }
printf("水费为%.2f元\n",cost); return 0; }