%02d得意思是什么?

来源:互联网 发布:iphone7销量数据 编辑:程序博客网 时间:2024/04/27 16:27

格式符%02d中2d前面的前导符0表示输出数据时,若左边有多余位,则补0。利用这种输出格式,编程输出下面的信息。


#include <stdio.h>typedef struct date{    int year;    int month;    int day;} DATE;typedef struct student{    long id;    char name[10];    char sex;    DATE birthday;    int score[4];} STUDENT;int main(){    STUDENT stu2 = {100310121,"王刚",'M', {1991,5,19}, {72,83,90,82}};    printf("stu2: %ld %s %c %d/%02d/%02d %d %d %d %d\n",           stu2.id,stu2.name,stu2.sex,           stu2.birthday.year,stu2.birthday.month,stu2.birthday.day,           stu2.score[0],stu2.score[1],stu2.score[2],stu2.score[3] );    return 0;}

2是宽度很简单。如果整数不够2列就补上0



0 0
原创粉丝点击