程序用C ++来寻找世纪年
在本教程中,我们将讨论一个寻找世纪的程序。
为此,我们将获得一年的服务。我们的任务是找到给定年份的世纪。
示例
#include <bits/stdc++.h>
using namespace std;
void find_century(int year){
//年份值只能是正数
if (year <= 0)
cout << "0 and negative is not allow"
<< "for a year";
else if (year <= 100)
cout << "1st century\n";
else if (year % 100 == 0)
cout << year/ 100 <<" century";
else
cout << year/ 100 + 1 << " century";
}
int main(){
int year = 2001;
find_century(year);
return 0;
}输出结果
21 century
热门推荐
10 财运虎年祝福语简短语
11 单亲爸爸春节祝福语简短
12 狗狗上厕所训练
13 植物种植祝福语简短
14 翻译考试祝福语朋友简短
15 个人周年庆简短祝福语
16 狗狗怎么训练
17 分别祝福语简短搞笑英文
18 生日广州男生祝福语简短