|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
#include<stdio.h>
void Print(int months[11],int length){
int i;
for(i=0;i<length;i++){
printf("%d月份:%d天\n",(i+1),months[i]);
}
}
int checkMonths(int *year){
int months[12]={1,2,3,4,5,6,7,8,9,10,11,12};
months[0]=31;
months[2]=31;
months[4]=31;
months[6]=31;
months[7]=31;
months[9]=31;
months[11]=31;
months[3]=30;
months[5]=30;
months[8]=30;
months[10]=30;
if(*year%4==0){
months[1]=29;
if(*year%4==0&&*year%100!=0){
months[1]=29;
}else{
months[1]=28;
}
}else{
months[1]=28;
}
Print(months,sizeof(months)/sizeof(int));
}
int main(){
int year;
printf("请输入年份\n");
scanf("%d",&year);
checkMonths(&year);
}
#include<stdio.h>
int main() {
long count=0;
int year1,year2,month1,month2,day1,day2;
int days[]= {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
printf("请输入您的生日\n");
scanf("%d-%d-%d",&year1,&month1,&day1);
printf("请输入今年日期\n");
scanf("%d-%d-%d",&year2,&month2,&day2);
while(year1<=year2) {
days[1]=(year1%400==0||(year1%400==0&&year1%100!=0))?29:28;
while(month1<=12) {
while(day1<=days[month1-1]) {
if(year1==year2&&month1==month2&&day1==day2) {
goto FINISH;
}
day1++;
count++;
}
day1=1;
month1++;
}
month1=1;
year1++;
}
FINISH:printf("你在这个世界上总共生存了%d天\n",count);
return 0;
}
#include<stdio.h>
int main() {
long count=0,count2;
int year1,year2,year3,month1,month2,month3,day1,day2,day3;
int days[]= {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
printf("请输入您的生日\n");
scanf("%d-%d-%d",&year1,&month1,&day1);
printf("请输入今年日期\n");
scanf("%d-%d-%d",&year2,&month2,&day2);
year3=year1+80;
month3=month2;
day3=day1;
while(1) {
days[1]=(year1%400==0||(year1%400==0&&year1%100!=0))?29:28;
while(month1<=12) {
while(day1<=days[month1-1]) {
if(year1==year2&&month1==month2&&day1==day2) {
count2=count;
printf("你在这个世界上总共生存了%d天\n",count2);
}
if(year1==year3&&month1==month3&&day1==day3) {
printf("活到80岁还剩%d\n",count-count2);
printf("你已经使用了还剩%2f\%的生命\n",(double)count2/count*100);
goto FINISH;
}
day1++;
count++;
}
day1=1;
month1++;
}
month1=1;
year1++;
}
FINISH:
return 0;
}
|
|