c语言 输入英文的星期几,再星期表中查找后输出对应的数字
输入英文的星期几,再星期表中查找后输出对应的数字。具体的算法是:若发现再表中某项相同,则输出该字符串再表中的位置(序号);若查到表尾仍不相同,则输出错误信息。星期表内容如...
输入英文的星期几,再星期表中查找后输出对应的数字。具体的算法是:若发现再表中某项相同,则输出该字符串再表中的位置(序号);若查到表尾仍不相同,则输出错误信息。
星期表内容如下:
0 sunday
1 monday
2 tuesday
3 wednesday
4 thursday
5 friday
6 saturday
程序中采用一个二维字符数组来存放星期表。数字定义如下,每个字符串所对应的数字即为该数组所在行的行号:
char week_day[][10]={"sunday","monday","tuesday","wednesday","thursday","friday","saturday"};
请根据上述数组定义完成程序。 展开
星期表内容如下:
0 sunday
1 monday
2 tuesday
3 wednesday
4 thursday
5 friday
6 saturday
程序中采用一个二维字符数组来存放星期表。数字定义如下,每个字符串所对应的数字即为该数组所在行的行号:
char week_day[][10]={"sunday","monday","tuesday","wednesday","thursday","friday","saturday"};
请根据上述数组定义完成程序。 展开
2个回答
展开全部
#include <stdio.h>
#include <string.h>
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");
}
——————
编译好了~~:)
#include <string.h>
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");
}
——————
编译好了~~:)
展开全部
#include
<stdio.h>
#include
<string.h>
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");
}
——————
编译好了~~:)
<stdio.h>
#include
<string.h>
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");
}
——————
编译好了~~:)
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询