برنامج المحاكاة تجربة رمي
حجر
النرد
input "how many times",n
no.4 = 0
for i = 1 to n
randomize timer
outcome = int( 6 * rnd(i)) + 1 print outcome;"
if outcome = 4 then
no.4 = no.4 + 1
end if
،
،
no of experiments
outcome of a throw
١٨٤
11.
>
C
counting how many times no. 4 appeared ..
next i
print print '
H
print "the total number of apperence of the requested no is"
print "
p = no.4 / n
; no.4
'computing the probability
print "with probability= "; p
end
مثال ٤ : أكتب برنامجا يحاكي تجربة رمي حجر ،نرد، اجعل البرنامج يـــــوم
بتكرار التجربة n من المرات n عدد صحيح معطى)، ثم يجد ويطبع الحادثة مجموع العدديين أكبر من m عدد معطى ، 7 مثلا "
الحل : كما في المثال السابق ولكن نستخدم دالة Randomize لإعطاء
أرقام عشوائية.
يأخذ البرنامج الشكل التالي:
ج٢ ص١٨٤