小白求助,问题在注释里
本帖最后由 吻你不厌 于 2020-11-2 20:20 编辑#include <stdio.h>
int main()
{
long count1 = 0, count2; // count用于存放一共活了多少天
int year1, year2, year3; // year1是你的生日年份,year2是今天的年份
int month1, month2, month3;
int day1, day2, day3;
int days[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
printf("请输入你的生日(如1988-05-20):");
scanf("%d-%d-%d", &year1, &month1, &day1);
printf("请输入今天的日期(如2016-03-28):");
scanf("%d-%d-%d", &year2, &month2, &day2);
year3 = year1 + 80;
month3 = month1;
day3 = day1;
while (1)
{
days = (year1 % 400 == 0 || (year1 % 4 == 0 && year1 % 100 != 0)) ? 29 : 28;
while (month1 <= 12)
{
while (day1 <= days)
{
if (year1 == year2 && month1 == month2 && day1 == day2)
{
count2 = count1;
printf("你在这个世界上总共生存了%d天\n", count2);
}
if (year1 == year3 && month1 == month3 && day1 == day3)
{
printf("如果能活到80岁,你还剩下%d天\n", count1 - count2);
printf("你已经使用了%.2f\%的生命,请好好珍惜剩下的时间!\n", (double)count2 / count1 * 100);//这里被转译的%为什么运行的时候打印不出来?难道是小甲鱼答案错了?还有就是(double)是什么意思?
goto FINISH;
}
day1++;
count1++;
}
day1 = 1;
month1++;
}
month1 = 1;
year1++;
}
FINISH: return 0;
} 注释打成反斜杠了,但不影响问题。。。 #define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
int main()
{
long count1 = 0, count2; // count用于存放一共活了多少天
int year1, year2, year3; // year1是你的生日年份,year2是今天的年份
int month1, month2, month3;
int day1, day2, day3;
int days[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
printf("请输入你的生日(如1988-05-20):");
scanf("%d-%d-%d", &year1, &month1, &day1);
printf("请输入今天的日期(如2016-03-28):");
scanf("%d-%d-%d", &year2, &month2, &day2);
year3 = year1 + 80;
month3 = month1;
day3 = day1;
while (1)
{
days = (year1 % 400 == 0 || (year1 % 4 == 0 && year1 % 100 != 0)) ? 29 : 28;
while (month1 <= 12)
{
while (day1 <= days)
{
if (year1 == year2 && month1 == month2 && day1 == day2)
{
count2 = count1;
printf("你在这个世界上总共生存了%d天\n", count2);
}
if (year1 == year3 && month1 == month3 && day1 == day3)
{
printf("如果能活到80岁,你还剩下%d天\n", count1 - count2);
printf("你已经使用了%.2f%%的生命,请好好珍惜剩下的时间!\n", (double)count2 / count1 * 100);//这里被转译的%为什么运行的时候打印不出来?难道是小甲鱼答案错了?还有就是(double)是什么意思?
goto FINISH;
}
day1++;
count1++;
}
day1 = 1;
month1++;
}
month1 = 1;
year1++;
}
FINISH: return 0;
} %%在c中表示%,我没听过小甲鱼的c,可能是版本问题或者小甲鱼日常小口胡{:10_266:} 当使用scanf对 double和float输入时:
double对应的是 %lf
float对应的是 %f
注:%f与%lf不可混用
当使用printf对double和float输出时:
%f 和 %lf 能够混用
摘录于:https://blog.csdn.net/qq_45567031/article/details/104815270?utm_medium=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-3.channel_param&depth_1-utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-3.channel_param 应该是编译器的问题(或同样的编译器不同版本),像我就打印出来了
(double)a,将a强制转化为double型 我就是来打酱油的
页:
[1]