国庆星期几
题目
1949 年的国庆节(10 月1日)是星期六。
今年(2012)的国庆节是星期一。
那么,从建国到现在,有几次国庆节正好是星期日呢?
不要求写出具体是哪些年,只要一个数目!
分析
先判断哪一年是闰年,然后整体天数对7进行整除余1便是星期日(注意:要对所有天数进行累加)
代码
#include <stdio.h>
#include <stdlib.h>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int a,b;
#判断闰年函数
void run(int x){
if(x%4==0 && x%100!=0 || x%400==0){
a=366;
}
a=365;
}
int main(int argc, char *argv[]) {
int year;
int temp = 0;
int i,j=0;
for(i=1950;i<=2012;i++){
run(i);
temp = temp + a; #依次对每一年进行累加
if(temp %7 == 1){
j++;
printf("%d\n",i); #我自己对符合条件的年份进行了打印
}
}
printf("%d",j);
return 0;
}