例子:
输入(dd mm yyyy):11 11 2011
输出:2011 年 11 月 11 日
这是正确的,但月份和年份之间有一个额外的数字
我不知道如何删除它。请帮忙!
#include <stdio.h>
int getDay(int day)
{
switch(day)
{
case 1: printf("%dst ", day); break;
case 2: printf("%dnd ", day); break;
case 3: printf("%drd ", day); break;
default: printf("%dth ", day); break;
}
}
int getMonth(int month)
{
switch(month)
{
case 1: printf("January "); break;
case 2: printf("February "); break;
case 3: printf("March "); break;
case 4: printf("April "); break;
case 5: printf("May "); break;
case 6: printf("June "); break;
case 7: printf("July "); break;
case 8: printf("August "); break;
case 9: printf("September "); break;
case 10: printf("October "); break;
case 11: printf("November "); break;
case 12: printf("December "); break;
default: printf("Invalid "); break;
}
}
int main()
{
int day, month, year;
printf("Enter date in dd mm yyyy format: ");
scanf("%d %d %d", &day, &month, &year);
day = getDay(day);
month = getMonth(month);
year = year;
printf("%d", day);
printf("%d", month);
printf("%d", year);
fflush(stdin);
getchar();
}