计算1000年至3000年之间的对称日

 计算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;
		}	
	}
}

 

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值