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