switch和数组两种方法对不同输入做不同响应
#include<stdio.h> int main(void) { int i; scanf("%d",&i); switch(i) { case 1: printf("who\n"); break; case 2: printf("what\n"); break; case 3: printf("when\n"); break; case 4: printf("where\n"); break; case 5: printf("why\n"); break; default: printf("don't know\n"); break; } return 0; }
#include<stdio.h> int main(void) { int i; char *str[5]={"who","what","when","where","why"}; scanf("%d",&i); if(i<=5&&i>=1) printf("%s\n",str[i-1]); else printf("don't know"); return 0; }
posted on 2018-02-26 19:01 yiludaifei 阅读(209) 评论(0) 编辑 收藏 举报