某人从1990-01-01开始三天打鱼两天晒网,编一个程序:任意输入一个日期 输出某人是在打渔还是晒网
入门新手,因为学的很少,只能用最基础的东西,写得很复杂,请帮忙看下错误出在哪里
C语言,三天打鱼两天晒网
答案:2 悬赏:10 手机版
解决时间 2021-02-13 19:51
- 提问者网友:精神病院里
- 2021-02-13 13:05
最佳答案
- 五星知识达人网友:孤老序
- 2021-02-13 13:47
#include <stdio.h>
int is_leap_year(int y)
{
if (y % 4 == 0 && y % 100 != 0 || y % 400 == 0)
return 1;
return 0;
}
int main(void)
{
int mon[13] = { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
int y, m, d;
int i, sum = 0;
scanf("%d%d%d", &y, &m, &d);
for (i = 1990; i < y; i++) {
if (is_leap_year(i))
sum++;
}
for (i = 1; i < m; i++) {
if (is_leap_year(i) && i == 2)
sum += 29;
else
sum += mon[i];
}
sum += d;
sum %= 5;
if (1 <= sum && sum <= 3)
printf("打鱼\n");
else
printf("晒网\n");
return 0;
}
int is_leap_year(int y)
{
if (y % 4 == 0 && y % 100 != 0 || y % 400 == 0)
return 1;
return 0;
}
int main(void)
{
int mon[13] = { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
int y, m, d;
int i, sum = 0;
scanf("%d%d%d", &y, &m, &d);
for (i = 1990; i < y; i++) {
if (is_leap_year(i))
sum++;
}
for (i = 1; i < m; i++) {
if (is_leap_year(i) && i == 2)
sum += 29;
else
sum += mon[i];
}
sum += d;
sum %= 5;
if (1 <= sum && sum <= 3)
printf("打鱼\n");
else
printf("晒网\n");
return 0;
}
全部回答
- 1楼网友:低音帝王
- 2021-02-13 14:07
#include #define max 100 #define leap(y) (y%4==0 && y%100!=0 || y%400==0) struct d{int y,m,d;}; long days(struct d d1,struct d d2) { int mon[2][13]= {{0,31,28,31,30,31,30,31,31,30,31,30,31}, {0,31,29,31,30,31,30,31,31,30,31,30,31}}; int i; long td=0; for(i=d1.y;i
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯