输入一个整数1~7,调用一个自己定义的函数,输出星期一~星期日;

c语言编程
2024-11-26 04:44:18
推荐回答(2个)
回答1:

main()
{
int i;
char *day_name(int n);
printf("input day No:\n");
scanf("%d",&i);
if(i<0) exit(1);
printf("day No:%2d-->%s\n",i,day_name(i));
}
char *day_name(int n)
{
static char *name[]={ "illegal day",
"monday",
"tuesday",
"wednesday",
"thursday",
"friday",
"saturday",
"sunday"};
return((n<1||n>7) ? name[0] : name[n]);
}

回答2:

#include "Stdio.h"
data(int n){
switch(n){
case 1:
printf("monday");break;
case 2: printf("tuesday");break;
case 3: printf("wednesday");break;
case 4: printf("thursday");break;
case 5: printf("friday");break;
case 6: printf("saturday");break;
case 7: printf("sunday");break;
}
}
main()
{
data(3);
getch();

}