用if、else if:
#includeint main() { int type; scanf("%d",&type); if(type==1){ printf("你好"); }else if(type==2){ printf("早上好"); }else if(type==3){ printf("晚上好"); }else if(type==4){ printf("再见"); }else{ printf("啊、什么啊?"); } return 0; }
用switch-case
#includeint main() { int type; scanf("%d",&type); switch(type){ case 1: printf("你好"); break; case2: printf("早上好"); break; case3: printf("晚上好"); break; case4: printf("再见"); break; default: printf("啊,什么啊?"); break; } return 0; }
左边比右边更OK ↓
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)