编写一个程序,提示用户输入3个整数值,分别代日,月,年。例如用户输入了12,31,2003.程序就以31stDecember2003的格式输出该日期。必须在日期值得后面加上th,nd,st和rd。
例如1st,2nd,3rd,4th,11th,12th,13th,14th,21st,22nd,23rd,24th。
#include"stdio.h"
int main(void) {
int x, y, z;
x = y = z = 0;
char *m[] = { "January","February","March","April","May","June","July","August","September","October","November","December" };
printf("请按日,月,年的顺序输入日期:");
scanf_s("%d%d%d", &x, &y, &z);
int d = x % 10;
if (d == 1 || d == 2 || d == 3) {
printf("您输入的日期是:%d%s%s%d.",x, (d % 10 == 1 ? "st" : (d % 10 == 2 ? "nd" : "rd")), m[y - 1], z);
}
else
printf("您输入的日期是:%dth%s%d.", x, m[y - 1], z);
getchar();
return 0;
}