Skip to content

Century From Year

Given a year, return the century it is in. The first century spans from the year 1 up to and including the year 100, the second - from the year 101 up to and including the year 200, etc.

Example

  • For year = 1905, the output should be

    century_from_year(year) = 20
  • For year = 1700, the output should be

    century_from_year(year) = 17

Chart

Solution

py
def century_from_year(year):
    return (year + 99) // 100


print(century_from_year(2001))
js
function centuryFromYear(year) {
  return Math.floor((year + 99) / 100);
}

console.log(centuryFromYear(1900));
ts
function centuryFromYear(year: number): number {
  return Math.floor((year + 99) / 100);
}

console.log(centuryFromYear(1900));
cs
using Internal;

static int centuryFromYear(int year)
{
  return ((year + 99) / 100);
}

Console.WriteLine($"{centuryFromYear(1901)}");

my thoughts are neither my employer's nor my wife's