C语言 源程序代码分析
从键盘上输入一个数字(0~7),输出一个对应的英文星期单词。输入一个怎么星期一到星期天全出来了,问题出在哪?求解
#include<stdio.h> int main() { int a; while (1) { printf("请任意输入一个1~7之间的数字:"); scanf("%d",&a); switch (a) { 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:printf("输入错误,请重新输入\n");break; } } return 0;是这样的么?
/****************************************************************************** 题目: 按“月/日/年”的格式接受用户输入的日期,然后按照“月 日, 年”的格式显示,其 中“月”用英文全名. 演示: 邮箱:mumu3w@ 时间:11/05/2015 ******************************************************************************/ #include <stdio.h> #include <ctype.h> int main(void){ const char *month[] = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"}; int dd, mm, yyyy; printf("Enter a date (mm/dd/yy): "); scanf("%d/%d/%d", &mm, &dd, &yyyy); printf("You entered the date %s %.2d, %4d", month[mm-1], dd, yyyy); return 0; }