ในบทช่วยสอนนี้ เราจะพูดถึงโปรแกรมค้นหาศตวรรษเป็นเวลาหนึ่งปี
สำหรับสิ่งนี้เราจะได้รับหนึ่งปี หน้าที่ของเราคือค้นหาศตวรรษที่ปีที่กำหนดตก
ตัวอย่าง
#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