int leap (int a)
{
if (a % 4 == 0 && a % 100 != 0 || a % 400 == 0)
return 1;
else
return 0;
}
int number (int year, int m, int d)
{
int sum = 0, i, j, k, a[12] =
{
31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31
};
int b[12] =
{
31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31
};
if (leap(year) == 1)
for (i = 0; i <= m - 1; i++)
sum += b[i];
else
for (i = 0; i <= m - 1; i++)
sum += a[i];
sum += d;
return sum;
}
if ((n % 5) < 4 && (n % 5) > 0)
printf("%d %d %d 打鱼", year, mouth, day);
else
printf("%d %d %d 晒网", year, mouth, day);
return 0;
运行结果如下
详细代码如下
#include
#include
int leap (int a)
{
if (a % 4 == 0 && a % 100 != 0 || a % 400 == 0)
return 1;
else
return 0;
}
int number (int year, int m, int d)
{
int sum = 0, i, j, k, a[12] =
{
31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31
};
int b[12] =
{
31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31
};
if (leap(year) == 1)
for (i = 0; i <= m - 1; i++)
sum += b[i];
else
for (i = 0; i <= m - 1; i++)
sum += a[i];
sum += d;
return sum;
}
int main ()
{
int year, mouth, day, n;
printf ("请输入年月日:\n");
scanf ("%d %d %d", &year, &mouth, &day);
n = number (year, mouth, day);
if ((n % 5) < 4 && (n % 5) > 0)
printf("%d %d %d 打鱼", year, mouth, day);
else
printf("%d %d %d 晒网", year, mouth, day);
return 0;
}