...程序按照用户的输入输出对应的星期几的英文,用switch...case结构...
发布网友
发布时间:2024-10-04 08:43
我来回答
共5个回答
热心网友
时间:2024-10-25 19:52
#include<stdio.h>
# include <stdlib.h>
# include <conio.h>
main()
{
char choose='\0',yes_no='\0';
do{
system("cls"); //清屏
printf("请输入0~7中的一个数字: \n ");
choose=getche();
printf("\n");
switch(choose)
{
case'1':printf("\n Monday\n");break;
case'2':printf("\n Tuesday\n");break;
case'3':printf("\n Wednesday\n");break;
case'4':printf("\n Thursday\n");break;
case'5':printf("\n Friday\n");break;
case'6':printf("\n Saturday\n");break;
case'7':printf("\n Sunday\n");break;
case'0':break;
default:printf(" %c为非法选项!\n",choose);
}
if(choose=='0')
break;
printf("\n 要继续输入数字吗(Y/N)?\n");
do{
yes_no=getch();
}while(yes_no!='Y'&&yes_no!='y'&&yes_no!='N'&&yes_no!='n');
}while(yes_no=='Y'||yes_no=='y');
}
热心网友
时间:2024-10-25 19:54
#inlcude<stdio.h>
#inlcude<string.h>
void main() { int n; char weekday[40];
scanf("%d",&n);
switch( n ) {
case 1: strcpy(weekday,"Monday"); break;
case 2: strcpy(weekday,"Tuesday"); break;
case 3: strcpy(weekday,"Wednesday"); break;
case 4: strcpy(weekday,"Thursday"); break;
case 5: strcpy(weekday,"Friday"); break;
case 6: strcpy(weekday,"Saturday"); break;
case 7: strcpy(weekday,"Sunday"); break;
default: strcpy(weekday,"无法判断"); break;
}
pritnf("%d: %s\n",n,weekday);
}
热心网友
时间:2024-10-25 19:53
int main()
{
char day;
day=getchar();
switch(day)
{
case '1':
{
printf("Monday\n");
break;
}
case '2':
// 后面类似。。(记得break)
// 重点:
default:
printf("非法输入\n");
}
return 0;
{
热心网友
时间:2024-10-25 19:55
#include <stdio.h>
#include <stdlib.h>
int main()
{
int day = 0;
printf("please input a number betweek 1~7\n");
scanf("%d",&day);
if(day<1||day>7)
{
printf("input error !\n");
exit(1);
}
switch(day)
{
case 1:
printf("Monday\n");
break;
case 2:
printf("Tuesday\n");
break;
case 3:
printf("Wednesday\n");
break;
case 4:
printf("Thursday\n");
break;
case 5:
printf("Friday\n");
break;
case 6:
printf("Saturday\n");
break;
case 7:
printf("sunday\n");
break;
default:
break;
}
热心网友
时间:2024-10-25 19:55
#include <stdio.h>
int main()
{
int day;
printf("请输入1-7之间任意的数字\n");
scanf("%d",&day);
while(day<1||day>7)
{
printf("请输入1-7之间任意的数字\n");
scanf("%d",&day);
}
switch(day)
{
case 1:printf("Monday\n");break;
case 2:printf("Tuesday\n");break;
case 3:printf("Wednesday\n");break;
case 4:printf("Thursday\n");break;
case 5:printf("Friday\n");break;
case 6:printf("Saturday\n");break;
case 7:printf("Sunday\n");break;
}
return 0;
}