“输出一个0~6的整数,转换为星期”怎样做
“输出一个0~6的整数,转换为星期”怎样做
“输出一个0~6的整数,转换为星期”怎样做
2015-12-14
#include<iostream.h>
int main()
{
int a;
cin>>a;
switch(a)
{
case 0:cout<<"Sunday"<<endl;
break;
case 1:cout<<"Monday"<<endl;
break;
case 2:cout<<"Tuseday"<<endl;
break;
case 3:cout<<"Wednesday"<<endl;
break;
case 4:cout<<"Thursday"<<endl;
break;
case 5:cout<<"Friday"<<endl;
break;
case 6:cout<<"Saturday"<<endl;
break;
default:cout<<"Please input 0~6"<<endl;
break;
}
return 0;
}
int i ;
printf("请输入一个0~6的数");
scanf("%d",&i);
if (i>=0&&i<=6) {
switch (i) {
case 0:
printf("星期日");
break;
case 1:
printf("星期一");
break;
case 2:
printf("星期二");
break;
case 3:
printf("星期三");
break;
case 4:
printf("星期四");
break;
case 5:
printf("星期五");
break;
case 6:
printf("星期六");
break;
default:
printf("输入有误");
break;
}
}
举报