PHP で九九の表を出力する

Blog.okuryu

Prev | PHP で九九の表を出力する | Next

Tags: php | Date: 2006-11-05T02:32:07+09:00 | Comments: 2 | Trackbacks: 0

最初に出した課題は掛け算の九九表を出力せよ、です。81回printする不届き者もいますので10行で、が条件。結構難しい。PHPの場合、HTMLのtableで出力するのが簡単なので「24」の項を太字にする、を次の課題にすると必要な構文はだいたい使うことになります。今まで何人かに九九表を書いてもらいましたがそれなりにいい課題なのでは、と思ってます。

zuzara : 友人がハッカーになるまで:自分のサービスを世に出す快感 」より

ちょっと自分でも書いてみた。

<?php
echo '<table>';
for( $i = 1; $i <= 9; $i++ ) {
  echo '<tr>';
  for( $j = 1; $j <= 9; $j++ ) echo $i * $j == 24 ? '<td><strong>' . $i * $j . '</strong></td>' : '<td>' . $i * $j . '</td>';
  echo '</tr>';
}
echo '</table>';
?>

とりあえず10行にはおさまった。他にも書き方あるんだろうか。

トラックバック

このエントリーのトラックバックURL:
http://www.okuryu.com/mt/mt-tb.cgi/193

コメント

bogdanlebu | 2008-04-07T04:14:14+09:00

I think that you really can judge people by the way they comment different stuff. Some people, even expressing negative thoughts, are still polite and they respect and understand other people. Some people are not even trying to be nice, they just don’t care. I think self-confident person will always act nice, no matter what other people do

sandeep | 2008-04-09T18:56:08+09:00

Do you fairly think this is news? I like and read your blog to get necessary information, but sometimes melancholy kills me

コメントを投稿

TypeKey を利用してコメントすることができますが、TypeKey ID をお持ちでない方もそのままコメントすることができます。






画像の中に見える文字を入力してください。


このサイトで公開しているものは クリエイティブ・コモンズ 帰属 - 同一条件許諾 2.5 の下でライセンスされています。