C++ 中查找一年所属世纪的程序
在本教程中,我们将探讨如何编写程序来查找一年的世纪。
为此,我们将提供一年。我们的任务是找出给定年份所属的世纪。
示例
#include <bits/stdc++.h>
using namespace std;
void find_century(int year){
//year values can only be positive
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
广告
数据结构
网络
关系型数据库管理系统
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP