浙大版《C语言程序设计(第3版)》题目集 练习7-9 计算天数 (15分)

浙大版《C语言程序设计(第3版)》题目集 练习7-9 计算天数 (15分)_第1张图片

#include 
int main()
{
    int a[][12] = {{31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31},
                   {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}};
    int leap, year, month, day, sum, i;
    scanf("%d/%d/%d", &year, &month, &day);
    leap = 0;
    if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0)
        leap = 1;
    sum = 0;
    for (i = 0; i < month - 1; i++)
    {
        sum += a[leap][i];
    }
    sum += day;
    printf("%d", sum);
    return 0;
}

你可能感兴趣的:(浙大版《C语言程序设计(第3版)》题目集 练习7-9 计算天数 (15分))