|
 |
|
ลองมาดูโจทย์ข้อนี้หน่อยนะครับ ง่ายๆ แต่ทำไม่ได้อะ เขียนโปรแกรมให้แสดงค่าตัวเลขตั้งแต่ 1 ถึง x |
|
 |
|
|
 |
 |
|
มะแน่จ่ายอ่ะนะ
ต้องรับค่าตัวแปรมาก่อนอย่างเช่น n=1
แล้วก้อกำหนดจำนวนรอบ =x ซึ่ง x=10
จากนั้นก้อทำลูป +ค่าทีละ 1 จนครบจำนวนรอบ x อ่ะแค่นี้อ่ะ
|
 |
 |
 |
 |
Date :
2009-08-03 12:45:37 |
By :
gummezaka |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (PHP)
<?php
function echonum($max,$n=1) {
if ($n<=$max)
{
echo $n."<br />";
echonum($max,$n+1);
}
}
echonum(4);
?>
|
 |
 |
 |
 |
Date :
2009-08-03 13:05:17 |
By :
ongsa |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (PHP)
<?php
for($x=1;$x<=10;$x++) {
echo $x . " ";
}
?>
|
 |
 |
 |
 |
Date :
2009-08-03 13:08:30 |
By :
gummezaka |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
แหะ แหะ โจทย์ไม่ได้บอกห้ามใช้ function ใช่มั้ยครับ
|
 |
 |
 |
 |
Date :
2009-08-03 13:08:41 |
By :
ongsa |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
อันข้างบนเปงแนวนอนนะ แต่ถ้าต้องการให้เปงแนวตั้งก้อเติม <br> เข้าไปอ่ะแบบนี้
Code (PHP)
<?php
for($x=1;$x<=10;$x++) {
echo $x . "<br> ";
}
?>
|
 |
 |
 |
 |
Date :
2009-08-03 13:10:30 |
By :
gummezaka |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
อิอิ นั้นสินะ ทำแบบไหนก้อถูกหมดแหล่ะค่ะ
|
 |
 |
 |
 |
Date :
2009-08-03 13:12:19 |
By :
gummezaka |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ใช้แบบ recursive สิครับ
|
 |
 |
 |
 |
Date :
2009-08-03 16:21:43 |
By :
naki |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ongsa ถูก
memee ผิด ห้ามใช้ for

|
 |
 |
 |
 |
Date :
2009-08-03 16:44:31 |
By :
lozomac |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
แปววว แงแง
|
 |
 |
 |
 |
Date :
2009-08-03 16:45:55 |
By :
gummezaka |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เจ๋งมากครับ แป้ปเดียวมีคนทำได้แล้ว ผมคิดทั้งวัน
|
 |
 |
 |
 |
Date :
2009-08-04 13:50:15 |
By :
cassanowa |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 04
|