請問變量day怎么賦初值?。?/h1>
2 回答

TA貢獻(xiàn)1993條經(jīng)驗(yàn) 獲得超6個(gè)贊
.#include <stdio.h>
int leapYear(int year) // 判斷是否為潤年
{
if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0)
return 1;
else
return 0;
}
void main()
{
int year, month;
int m[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
printf ("請輸入日期(格式:年 月):");
scanf ("%d%d", &year, &month);
if (leapYear(year)) m[1] += 1;
printf ("%d年%d月共有%d天\n", year, month, m[month - 1]);
}

TA貢獻(xiàn)1806條經(jīng)驗(yàn) 獲得超8個(gè)贊
#include<iostream>
using namespace std;
int isLeap(int year)
{
if( year%400 == 0 || (year %4 == 0 && year %100 !=0))
{
return 1;
}
else
{
return 0;
}
}
int main()
{
int year;
int month;
int a[12]={31,28,31,30,31,30,31,31,30,31,30,31};
cout<<"please input the year"<<endl;
cin>>year;
cout<<"please input the month"<<endl;
cin>>month;
if(isLeap(year))
{
a[1] = a[1] +1;
}
cout<<"days = "<<a[month-1]<<endl;
cin.get();
cin.get();
return 0;
}
- 2 回答
- 0 關(guān)注
- 178 瀏覽
添加回答
舉報(bào)