c语言 输入英文的星期几,再星期表中查找后输出对应的数字

2024-11-26 06:35:03
推荐回答(2个)
回答1:

#include
#include
void main()
{
char a[10];
char week_day[][10]={"sunday","monday","tuesday","wednesday","thursday","friday","saturday"};
printf("请输入一个星期的单词:\n");
gets(a);

int i;
for(i=0;i<7;i++)
{
if(strcmp(a,week_day[i])==0)
break;
}
if(i<7)
printf("%d\n",i);
else
printf("ERROR!\n");
}

——————
编译好了~~:)

回答2:

#include

#include

void
main()
{
char
a[10];
char
week_day[][10]={"sunday","monday","tuesday","wednesday","thursday","friday","saturday"};
printf("请输入一个星期的单词:\n");
gets(a);
int
i;
for(i=0;i<7;i++)
{
if(strcmp(a,week_day[i])==0)
break;
}
if(i<7)
printf("%d\n",i);
else
printf("ERROR!\n");
}
——————
编译好了~~:)