就单单输入阿拉伯数字我用Switch语句和for语句就可以了 偏偏出个题目要英文数字(one two three four five six seven:)对应求星期几
用Switch或者for那种
就单单输入阿拉伯数字我用Switch语句和for语句就可以了 偏偏出个题目要英文数字(one two three four five six seven:)对应求星期几
用Switch或者for那种
做个数组来存储,然后用序号做switch的判定就可以了。
代码如下:
#include <stdio.h>
#include <string.h>
int main()
{
char mm[][20]={"one","two", "three", "four" ,"five", "six", "seven"};
int i;
char buf[20];
scanf("%s",buf);
for (i=0;i<7;i++)
{
if(strcmp(mm[i],buf)==0)
break;
}
switch(i)
{
case 0:
printf("星期一\n");break;
case 1:
printf("星期二\n");break;
case 2:
printf("星期三\n");break;
case 3:
printf("星期四\n");break;
case 4:
printf("星期五\n");break;
case 5:
printf("星期六\n");break;
case 6:
printf("星期日\n");break;
default:
printf("输入错误\n");break;
}
return 0;
}