romeinse-cijfers
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?php
# Transfer an integer to Roman numarals
# (1=I, 2=II, 5=V, 10=X, 50=L, 100=C, 500=D, 1000=M)
# Input: (1 to 3999)
#
function roman_numerals($number) {
if ($number > 0 and $number <= 3999) {
$rest = $number;
$roman_numerals = '';
while ($rest >= 1000) {
$roman_numerals = $roman_numerals . 'M';
$rest = $rest - 1000;
}
while ($rest >= 900) {
$roman_numerals = trim($roman_numerals . 'CM');
$rest = $rest - 900;
}
while ($rest >= 500) {
$roman_numerals = trim($roman_numerals . 'D');
$rest = $rest - 500;
}
while ($rest >= 400) {
$roman_numerals = trim($roman_numerals . 'CD');
$rest = $rest - 400;
}
while ($rest >= 100) {
$roman_numerals = trim($roman_numerals . 'C');
$rest = $rest - 100;
}
while ($rest >= 90) {
$roman_numerals = trim($roman_numerals . 'XC');
$rest = $rest - 90;
}
while ($rest >= 50) {
$roman_numerals = trim($roman_numerals . 'L');
$rest = $rest - 50;
}
while ($rest >= 40) {
$roman_numerals = trim($roman_numerals . 'XL');
$rest = $rest - 40;
}
while ($rest >= 10) {
$roman_numerals = trim($roman_numerals . 'X');
$rest = $rest - 10;
}
while ($rest >= 9) {
$roman_numerals = trim($roman_numerals . 'IX');
$rest = $rest - 9;
}
while ($rest >= 5) {
$roman_numerals = trim($roman_numerals . 'V');
$rest = $rest - 5;
}
while ($rest >= 4) {
$roman_numerals = trim($roman_numerals . 'IV');
$rest = $rest - 4;
}
while ($rest > 0) {
$roman_numerals = trim($roman_numerals . 'I');
$rest = $rest - 1;
}
}
else
{
$roman_numerals = 'Error: Input function roman_numarals() moet zijn >=0 en <= 3999!';
}
return $roman_numerals;
}
#echo roman_numerals(1999)
?>
# Transfer an integer to Roman numarals
# (1=I, 2=II, 5=V, 10=X, 50=L, 100=C, 500=D, 1000=M)
# Input: (1 to 3999)
#
function roman_numerals($number) {
if ($number > 0 and $number <= 3999) {
$rest = $number;
$roman_numerals = '';
while ($rest >= 1000) {
$roman_numerals = $roman_numerals . 'M';
$rest = $rest - 1000;
}
while ($rest >= 900) {
$roman_numerals = trim($roman_numerals . 'CM');
$rest = $rest - 900;
}
while ($rest >= 500) {
$roman_numerals = trim($roman_numerals . 'D');
$rest = $rest - 500;
}
while ($rest >= 400) {
$roman_numerals = trim($roman_numerals . 'CD');
$rest = $rest - 400;
}
while ($rest >= 100) {
$roman_numerals = trim($roman_numerals . 'C');
$rest = $rest - 100;
}
while ($rest >= 90) {
$roman_numerals = trim($roman_numerals . 'XC');
$rest = $rest - 90;
}
while ($rest >= 50) {
$roman_numerals = trim($roman_numerals . 'L');
$rest = $rest - 50;
}
while ($rest >= 40) {
$roman_numerals = trim($roman_numerals . 'XL');
$rest = $rest - 40;
}
while ($rest >= 10) {
$roman_numerals = trim($roman_numerals . 'X');
$rest = $rest - 10;
}
while ($rest >= 9) {
$roman_numerals = trim($roman_numerals . 'IX');
$rest = $rest - 9;
}
while ($rest >= 5) {
$roman_numerals = trim($roman_numerals . 'V');
$rest = $rest - 5;
}
while ($rest >= 4) {
$roman_numerals = trim($roman_numerals . 'IV');
$rest = $rest - 4;
}
while ($rest > 0) {
$roman_numerals = trim($roman_numerals . 'I');
$rest = $rest - 1;
}
}
else
{
$roman_numerals = 'Error: Input function roman_numarals() moet zijn >=0 en <= 3999!';
}
return $roman_numerals;
}
#echo roman_numerals(1999)
?>