1.%02d的理解是运用。
逻辑理解:如果出现输出的变量小于两位数,那么在第二位上填0;
#include<stdio.h>
int main()
{
int number=0;
scanf("%d",&number);
int datayear=number/10000;
int datamonth=number/100%100;
int datadate=number%100;
printf("year=%d\n",datayear);
printf("month=%02d\n",datamonth);
printf("date=%d\n",datadate);
return 0;
}
输入:20200220
输出结果:
方法2实现这个功能。
scanf("%4d%2d%2d",&year,&month,&day);
#include<stdio.h>
int main()
{
int year,month,date;
scanf("%4d%2d%2d",&year,&month,&date);
//int datayear=number/10000;
//int datamonth=number/100%100;
//int datadate=number%100;
printf("year=%d\n",year);
printf("month=%02d\n",month);
printf("date=%d\n",date);
return 0;
}