C语言程序设计 输入数字1-7,输出对应的星期几(switch) 30
2个回答
展开全部
程序流程如下:
1 输入变量a;
2 对变量a进行判断(switch(a));
3 根据a值输出对应的字符串;
4 程序结束。
代码如下:
#include <stdio.h>
int main()
{
int a;
scanf("%d",&a);//输入a
switch(a)
{
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;
case 7:
printf("星期日\n");
break;
default:
printf("错误输入\n");
break;
}
return 0;
}
展开全部
#include <stdio.h>
int main()
{
char *a[]={"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"};
int i;
scanf("%d",&i);
switch(i)
{
case 1: printf("%s\n",a[i-1]);break;
case 2: printf("%s\n",a[i-1]);break;
case 3: printf("%s\n",a[i-1]);break;
case 4: printf("%s\n",a[i-1]);break;
case 5: printf("%s\n",a[i-1]);break;
case 6: printf("%s\n",a[i-1]);break;
case 7: printf("%s\n",a[i-1]);break;
}
return 0;
}
int main()
{
char *a[]={"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"};
int i;
scanf("%d",&i);
switch(i)
{
case 1: printf("%s\n",a[i-1]);break;
case 2: printf("%s\n",a[i-1]);break;
case 3: printf("%s\n",a[i-1]);break;
case 4: printf("%s\n",a[i-1]);break;
case 5: printf("%s\n",a[i-1]);break;
case 6: printf("%s\n",a[i-1]);break;
case 7: printf("%s\n",a[i-1]);break;
}
return 0;
}
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询