C语言数组作业
#include<stdio.h>void Print(int months,int length){
int i;
for(i=0;i<length;i++){
printf("%d月份:%d天\n",(i+1),months);
}
}
int checkMonths(int *year){
int months={1,2,3,4,5,6,7,8,9,10,11,12};
months=31;
months=31;
months=31;
months=31;
months=31;
months=31;
months=31;
months=30;
months=30;
months=30;
months=30;
if(*year%4==0){
months=29;
if(*year%4==0&&*year%100!=0){
months=29;
}else{
months=28;
}
}else{
months=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=(year1%400==0||(year1%400==0&&year1%100!=0))?29:28;
while(month1<=12) {
while(day1<=days) {
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=(year1%400==0||(year1%400==0&&year1%100!=0))?29:28;
while(month1<=12) {
while(day1<=days) {
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;
}
页:
[1]