#include <vector>
#include <iomanip> / tw()的頭文件
using namespace std;
bool IsLeapYear(int year) //判斷是否是閏年
{
if( (year%4==0 && year%100!=0) || (year%400==0) )
return true;
else
return false;
}
void main()
{
int year,month,a[31];
cout<<"請輸入年:";
cin>>year;
cout<<"請輸入月:";
cin>>month;
if(month==2)
{
if(IsLeapYear(year)==true) //是閏年
{
for(int i=1; i<=28; i++)
{
cout<<setw(4)<<(a[i]=i);
if(i%7==0) cout<<endl;
}
cout<<endl;
}
else //不是閏年
{
for(int i=1; i<=29; i++)
{
cout<<setw(4)<<(a[i]=i);
if(i%7==0) cout<<endl;
}
cout<<endl;
}
}
else if(month==4 || month==6 || month==9 || month==11)
{
for(int i=1; i<=30; i++)
{
cout<<setw(4)<<(a[i]=i);
if(i%7==0) cout<<endl;
}
cout<<endl;
}
else
{
for(int i=1; i<=31; i++)
{
cout<<setw(4)<<(a[i]=i);
if(i%7==0) cout<<endl;
}
cout<<endl;
}
}
有什麽不明白的,在線問我