编写函数:二十一世纪

Description

每一百年是一个世纪。公元1年至99年是第一个世纪,公元100年至199年是第二个世纪……以此类推,19xx年是二十世纪,二十一世纪是2000年开始的。

现在编写一个程序计算一个年份是属于哪一个世纪。

--------------------------------------------------------------------

 

请根据“Append Code”完成程序。append.c中调用了一个结构体类型struct date和2个函数get_date()和put_century()。用C语言或C++编写自定义类型和函数实现,2个函数的原型为:

      int get_date(struct date *dt);

      功能:形参dt是一个结构体变量的指针,用于输入日期。

      put_century(struct date dt);

      功能:按格式输出dt所处的世纪。

 函数的调用格式见“Append Code”。

 

Input

输入格式为y/m/d,其中y、m、d是三个正整数表示年月日,均为合法日期。

 

Output

输出为一行“in the ??? century”,其中“???”表示序数(第几个)。

在序数xx(第xx个)中:个位数为1的是“st”结尾,为2的是“nd”结尾,为3的是“rd”结尾,为4~9和0的都是“th”结尾。

 

Sample Input

2018/12/30

Sample Output

in the 21st century

HINT

 

Append Code

 
 

#include <stdio.h>

struct date {
    int year, month, day;
};

int get_date(struct date* dt)
{
    scanf("%d/%d/%d", &(dt->year), &(dt->month), &(dt->day));
}

int put_century(struct date dt)
{
    int sj = dt.year / 100 + 1;
    if (sj % 10 == 1)
        printf("in the %dst century", sj);
    else if (sj % 10 == 2)
        printf("in the %dnd century", sj);
    else if (sj % 10 == 3)
        printf("in the %drd century", sj);
    else
        printf("in the %dth century", sj);
}


 

 

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值