请你尝试用C语言编写一个程序: 输入三个整数表示年、月、日,计算从该年的元旦算起到当日是第几天。 如输入 2019-1-1,输出1 【输入输出样例】 输入1: 2019-01-01 输出1: 1 输入2: 2019-3-6 输出2: 65 注意,要考虑闰年2月29天。
时间: 2023-05-27 14:04:39 浏览: 61
```c
#include <stdio.h>
// 判断是否为闰年
int isLeapYear(int year) {
return (year % 4 == 0 && year % 100 != 0) || year % 400 == 0;
}
int main() {
int year, month, day;
int daysOfMonth[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; // 每个月的天数
int i, sum = 0;
scanf("%d-%d-%d", &year, &month, &day);
for (i = 1; i < month; i++) {
sum += daysOfMonth[i];
}
sum += day;
if (isLeapYear(year) && month > 2) { // 是闰年且月份大于2月
sum++;
}
printf("%d\n", sum);
return 0;
}
```
相关问题
用c语言编写一个程序:输入三个整数,按由小到大的顺序输出。
以下是用 C 语言编写的程序,可以实现输入三个整数,按由小到大的顺序输出:
```c
#include <stdio.h>
int main() {
int a, b, c;
printf("请输入三个整数:\n");
scanf("%d%d%d", &a, &b, &c);
if (a > b) {
int t = a;
a = b;
b = t;
}
if (a > c) {
int t = a;
a = c;
c = t;
}
if (b > c) {
int t = b;
b = c;
c = t;
}
printf("由小到大的顺序输出为:%d %d %d\n", a, b, c);
return 0;
}
```
希望能够帮到您!
C语言编写一个程序:输入一个整数n,计算输出1+2+3+……+n的和
```c
#include <stdio.h>
int main() {
int n, sum = 0;
printf("请输入一个整数n:");
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
sum += i;
}
printf("1到%d的和为:%d\n", n, sum);
return 0;
}
```