#include "stdio.h"void main(){int g;printf("enter a mark");scanf("%d",&g);printf("g=%d: ",g);switch(g/10){case 10: case 9: printf("A\n");break; case 8: printf("B\n");break; case 7: printf("C\n");break; default : printf("D\n");break;}}这个运行得很好但是为什么我改成下面这样(直接输入分数,不除以10)就不行了呢?#include "stdio.h"void main(){int g;printf("enter a mark");scanf("%d",&g);printf("g=%d: ",g);switch(g){case 100: case 90: printf("A\n");break; case 80: printf("B\n");break; case 70: printf("C\n");break; default : printf("D\n");break;}}求解答
当然不行了 上面的之所以可以是因为整形除法不保留小数位 例如85/10 == 8 下面的程序只有输入整十数如70、80才能执行相关的语句
温馨提示:答案为网友推荐,仅供参考