计算1000年至3000年之间的对称日
思路:遍历,寻找判断对称日期。
嵌套循环遍历,函数判断,函数整合。
#include<stdio.h>
#include<math.h>
int Day(int a,int b); //该函数能够得出某月中天数。
int XF(int c,int d); //该函数能够将某月某日倒序成整数。
int HB(int e,int f,int g);//该函数能够将某年某月某日合并成整数 。
int main()
{
int year,month,day,count=0;//'year'为年,'month'为月,'day'为日,'count'为计数器。
printf("\n--------计算1000年至3000年之间的对称日:--------\n");
system("color 0b");
for(year=1000;year<=3000;year++){
for(month=1;month<=12;month++){
for(day=1;day<=Day(year,month);day++){
if(year==XF(month,day)){
printf("%-16d",HB(year,month,day));//给予每个数十六宽度并右对齐。
count++;
if(count!=0&&count%5==0){
printf("\n");
}
}
}
}
}
printf("\n--------共计有%d个对称日--------\n",count);
}
int HB(int e,int f,int g){
int u;
u=e*pow(10,4)+f*pow(10,2)+g;
return u;
}
int XF(int c,int d){
int m;
m=(d%10)*1000+(d/10)*100+(c%10)*10+(c/10)*1;
return m;
}
int Day(int a,int b)
{
if(a%4==0&&a%100!=0||a%400==0){
if(b==2){
return 29;
}
if(b==4||b==6||b==9||b==11){
return 30;
}
else{
return 31;
}
}
else{
if(b==2){
return 28;
}
if(b==4||b==6||b==9||b==11){
return 30;
}
else{
return 31;
}
}
}