Re: I need help on Number Based Repetition



wow, that's a lot clearer now, but the bad news is: I turned in the HW 15 minutes ago :(

the good news is, I have made a change in my program after much unnecessary thinking, here it is (it's somewhat similar to yours but I think it's actually shorter, and the value actually comes out to be 3.14xxx when I input 1,000,000 as the variable n):

function p = mypi( n )
o = 0;
for k = 1:n
x = rand;
y = rand;
l = sqrt(rand^2 + rand^2);
if l <= 1
o = o + 1/n;
end
p = 4*o;
end
.



Relevant Pages