Entry
How do you print a mulitiplication table using bases(ex..2 or 10)?
Jun 12th, 2005 13:23
mario, maryann,
/*
Is this what you were looking for? This is for base 10.
This code will print a simple multiplication table:
For other bases, From the PHP manual:
//
If you use the octal notation, you must precede the number with a 0
(zero), to use hexadecimal notation precede the number with 0x.
//
Example:
If you do - echo 0x1 * 0xa - you'll get 10
If you do - echo 0x2 * 0xa - you'll get 20
*/
$number=3; // the table you want to see
for ($a=1;$a<11;$a++)
{
echo $number . '*' . $a.': ' .$number * $a .'<br />';
}
/* Will print
3*1: 3
3*2: 6
3*3: 9
3*4: 12
3*5: 15
3*6: 18
3*7: 21
3*8: 24
3*9: 27
3*10: 30
*/