要求:90以上为A,80以上B,70以上C,70以下D拜托各位大神

#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才能执行相关的语句
温馨提示:答案为网友推荐,仅供参考

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网