【题目】输出出生年月日

题目:

三行,第一行为出生年份,第二行为出生月份,第三行为出生日期,输出是如果月份或天数只有一位数,需要在前面补0。 

示例: 

输入:

20040901

输出:

year=2004

month=09

date=01

备注:

通过scanf函数的%m格式控制可以指定输入域宽,输入数据域宽(列数),并按此宽度截取所需数据,通过printf函数的%0格式控制符,输出数值时在左面不使用的位置自动填0.

#include<stdio.h>
int main()
{
	int year = 0;
	int month = 0;
	int date = 0;
	scanf("%4d%2d%2d", &year, &month, &date);
	printf("year=%4d\n", year);
	printf("month = %02d\n", month);
	printf("date=%02d\n",date);
	return 0;

 

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
下面是一个示例代码,实现了题目要求的功能: ```c #include <stdio.h> #include <stdlib.h> #include <string.h> #define MAX_NAME_LEN 20 // 定义学生结构体 struct student { char name[MAX_NAME_LEN]; int score; int year; int month; int day; }; // 比较函数,用于qsort排序 int compare(const void *a, const void *b) { struct student *s1 = (struct student *) a; struct student *s2 = (struct student *) b; return s2->score - s1->score; } int main() { struct student stu[5]; int i; // 输入学生信息 for (i = 0; i < 5; i++) { printf("请输入第%d个学生的信息:\n", i + 1); printf("姓名:"); scanf("%s", stu[i].name); printf("分数:"); scanf("%d", &stu[i].score); printf("出生年月日(格式为yyyy mm dd):"); scanf("%d %d %d", &stu[i].year, &stu[i].month, &stu[i].day); } // 按分数降序排序 qsort(stu, 5, sizeof(struct student), compare); // 输出学生信息 printf("按分数降序排列的学生信息如下:\n"); for (i = 0; i < 5; i++) { printf("姓名:%s,分数:%d,出生年月日:%d年%d月%d日\n", stu[i].name, stu[i].score, stu[i].year, stu[i].month, stu[i].day); } return 0; } ``` 运行结果示例: ``` 请输入第1个学生的信息: 姓名:Tom 分数:90 出生年月日(格式为yyyy mm dd):2001 3 14 请输入第2个学生的信息: 姓名:Jack 分数:80 出生年月日(格式为yyyy mm dd):2002 4 15 请输入第3个学生的信息: 姓名:Lucy 分数:95 出生年月日(格式为yyyy mm dd):2001 2 1 请输入第4个学生的信息: 姓名:Mike 分数:85 出生年月日(格式为yyyy mm dd):2003 6 12 请输入第5个学生的信息: 姓名:Lily 分数:92 出生年月日(格式为yyyy mm dd):2000 9 23 按分数降序排列的学生信息如下: 姓名:Lucy,分数:95,出生年月日:2001年2月1日 姓名:Lily,分数:92,出生年月日:2000年9月23日 姓名:Tom,分数:90,出生年月日:2001年3月14日 姓名:Mike,分数:85,出生年月日:2003年6月12日 姓名:Jack,分数:80,出生年月日:2002年4月15日 ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

看着不爽

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值