int y = 0, m = 0, d = 0; int sum = 0;//用来存储其位这一年的第几天 printf("第七题:请输入年月日:"); scanf("%d%d%d", &y, &m, &d); int a[12] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; int b[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; if (y % 400 == 0 || (y % 4 ==0 && y % 100 != 0)) { for (int j = 0; j < m - 1; j++) { sum += a[j]; } sum += d; } else { for (int j = 0; j < m - 1; j++) { sum += b[j]; } sum += d; } printf("%d年%d月%d日是这一年的第%d天\n", y, m, d, sum);
原文地址:http://blog.csdn.net/andyknow/article/details/42009671