求将一段C++代码改成C语言的 我就剩10分了 不好意思

2024-12-04 19:44:56
推荐回答(2个)
回答1:

#include
#include
int n;
int month[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
char week[7][20] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
int y, m, d;

int IsLeapYear(int year) {
if (year % 400 == 0 || (year % 4 == 0 && year % 100 != 0)) return 1;
return false;
}

int Run() {
++n;
int w = n;
for (int i = 2000; ; ++i) {
if (IsLeapYear(i)) {
if (n - 366 <= 0) {
y = i;
break;
}
else n -= 366;
}

else {
if (n - 365 <= 0) {
y = i;
break;
}
else n -= 365;
}
}
if (IsLeapYear(y)) month[1] = 29;
else month[1] = 28;
for (int i = 0; i < 12; ++i) {
if (n - month[i] <= 0) {
m = i + 1;
break;
}
else n -= month[i];
}
d = n;
printf("%d",y);
printf("-");
if (m < 10)
printf("0");
printf("%d",m);
printf("-");
if (d < 10)
printf("0");
printf("%d",d);
printf("%d", week[(w + 5) % 7] );
printf("\n");
return 0;
}

int main() {
scanf("%d",&n) ;
while (n != -1)
{
Run();
}
return 0;
}

回答2:

你的代码想表达什么意思?保证无错吗?改成C后又有什么要求?