编程题;从键盘上输入1至7之间的整数,输入1输出星期一,输入二输出星

2024-11-26 04:42:28
推荐回答(2个)
回答1:

#include void main(){ int a; printf("请输入整数:"); scanf("%d",a); switch(a){ case 1: printf("星期一");break; case 2: printf("星期二");break; case 3: printf("星期三");break; case 4: printf("星期四");break; case 5: printf("星期五");break; case 6: printf("星期六");break; case 7:printf("星期日");break; default: printf("输入整数错误");}}

回答2:

输入1到7之间的值,输出星期几,其它值则退出程序。
c 语言程序如下:
#include
int main()
{
char s[8][16]={" ","Monday","Tuesday","Wednesday",
"Thursday","Friday","Saturday","Sunday" };
int i;
while(1){
printf("input one int value between 1 to 7, other value exit:");
scanf("%d",&i);
if (i<=0 || i>7) return 0;
printf("%s\n\n",s[i]);
}
return 0;
}