Q:

Write a script that will generate random integers in the range from 0 to 50, and print them, until one is finally generated that is greater than 25. The script should print how many attempts it took

0

Write a script that will generate random integers in the range from 0 to 50, and print them, until one is finally generated that is greater than 25. The script should print how many attempts it took. 

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Ch5Ex21.m

rani = randi([0 50]);

fprintf('The integer is %d\n', rani)

count = 1;

while rani <= 25

 rani = randi([0 50]);

 fprintf('The integer is %d\n', rani)

 count = count + 1;

end

fprintf('Yay, a %d! It took %d tries\n', rani, count)

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now