本月有几天
#include<iostream>
using namespace std;
int main()
{
int year,month,days;
cout<<"year";
cin>>year;
cout<<"month";
cin>>month;
switch(month)
{
case 2:
if(year%4==0&&year%100!=0||year%400==0)
{
days=29;
}
else
{
days=28;
}
break;
case 1:days=31;break;
case 3:days=31;break;
case 4:days=30;break;
case 5:days=31;break;
case 6:days=30;break;
case 7:days=31;break;
case 8:days=31;break;
case 9:days=30;break;
case 10:days=31;break;
case 11:days=30;break;
case 12:days=31;break;
}
cout<<"本月有"<<days<<"天"<<endl;
return 0;
}
水仙花数
<pre name="code" class="cpp">#include <iostream>
using namespace std;
int main()
{
int i, a, b, c;
for(i = 100; i < 1000; i++)
{
a = i / 100; //百位数
b = i / 10 % 10; //十位数
c = i % 10; //个位数
if(a * a * a + b * b * b + c * c * c == i)
cout << i << endl;
}
return 0;
}