输入年月日,显示这一天是这一年第几天
时间: 2023-12-01 09:41:19 浏览: 133
以下是两种实现输入年月日,显示这一天是这一年第几天的方法:
方法一:使用C语言实现
```c
#include <stdio.h>
int main() {
int year, month, day;
int days = 0;
scanf("%d%d%d", &year, &month, &day);
days += day;
switch(month) {
case 12: days += 30;
case 11: days += 31;
case 10: days += 30;
case 9: days += 31;
case 8: days += 31;
case 7: days += 30;
case 6: days += 31;
case 5: days += 30;
case 4: days += 31;
case 3:
if(((year % 4 == 0 && year % 100 != 0) || year % 400 == 0)) days += 29;
else days += 28;
case 2: days += 31;
}
printf("%d\n", days);
return 0;
}
```
方法二:使用Python实现
```python
x = int(input("请输入年份:"))
y = int(input("请输入月份:"))
z = int(input("请输入日期:"))
if x > 0 and y > 1 and y <= 12 and z > 0 and z <= 30:
print(f"该日期是{x}年的第{(y-1)*30+z}天")
elif x > 0 and y == 1 and z > 0 and z <= 30:
print(f"该日期是{x}年的第{z}天")
```
阅读全文