[PHP 기초] 구구단표 만들기 > 개발자팁

개발자팁

개발과 관련된 유용한 정보를 공유하세요.
질문은 QA에서 해주시기 바랍니다.

[PHP 기초] 구구단표 만들기 정보

기타 [PHP 기초] 구구단표 만들기

본문

for문과 sprintf를 이용한 구구단표입니다.

- 소 스 -

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=euc-kr">
<title>구구단을 외자</title>
<style type=text/css>
td { font-size:12px; font-family:굴림체; color:#0000FF; line-height:1.3; }
</style>
</head>
<body bgcolor=#FFFFFF>
<table border=0 width=720 bgcolor=#F0F0F0>
<tr>
<?
for($dan=2; $dan<=9; $dan++) {
    echo "<td align=center bgcolor=#C0C0C0>$dan 단</td>\n";
}
?>
</tr>
<?
// 구구단
for($gop=1; $gop<=9; $gop++) {
    echo "<tr>";
    for($dan=2; $dan<=9; $dan++) {
          $format = sprintf("%d * %d =&nbsp;%2d", $dan, $gop, $dan * $gop);
          echo "<td align=center bgcolor=#F0F0F0>$format</td>\n";
    }
    echo "</tr>\n";
}
?>
</table>
</body>
</html><div class='small'>[이 게시물은 관리자님에 의해 2011-10-31 17:12:10 PHP & HTML에서 이동 됨]</div>
추천
0
  • 복사

댓글 0개

© SIRSOFT
현재 페이지 제일 처음으로