C語言經典100題(手把手 編程)
可以在嗶哩嗶哩找到
已解決的天數:一,二,五,六
下面的都是模模糊糊的
可以學學這些算法,我是算法白癡,但是我不是白癡,可以學!
第三天(未解決)
第四天
#include <stdio.h>// 判斷是否為閏年
int isLeapYear(int year) {return (year % 4 == 0 && year % 100!= 0) || (year % 400 == 0);
}int main() {int year, month, day;int days_in_month[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};int total_days = 0;printf("請輸入年月日:");scanf("%d %d %d", &year, &month, &day);// 判斷閏年,更新二月天數if (isLeapYear(year)) {days_in_month[1] = 29;}// 計算天數for (int i = 0; i < month - 1; i++) {total_days += days_in_month[i];}total_days += day;printf("這是第%d天\n", total_days);return 0;
}