cybersecurity · beginner · ~15 min · safe pentest lab
Compute an inclusive range size.
Compute how many ports a (loopback-only) scan would cover, so you can bound and rate-limit it.
Implement int port_count(int lo, int hi) that returns the number of ports in the inclusive range [lo, hi], or 0 if hi < lo.
lo, hi: the inclusive range bounds.Returns int: hi - lo + 1 when hi >= lo, otherwise 0.
port_count(1, 1024) -> 1024
port_count(80, 80) -> 1
port_count(100, 10) -> 0 (empty range)
lo == hi) has count 1.hi < lo) has count 0.Two ints: the inclusive bounds lo and hi.
An int: the inclusive range size, or 0 if hi < lo.
Inclusive: hi - lo + 1 when hi >= lo, else 0.
int port_count(int lo, int hi) {
/* TODO */
return 0;
}
Solve this exercise in the browser editor — compile and run against the test harness, no setup required.