Number guessing game with integers
조회 수: 8 (최근 30일)
이전 댓글 표시
답변 (1개)
David Hill
2019년 12월 23일
r = randi([1,10]);
numb = 0;
n = 0;
Numb=[];
while numb ~= r
numb = input('Guess the number between 1 and 10: ');
if ~ismember(numb,Numb)
n = n+1;
Numb=[Numb,numb];
end
if numb < r
fprintf('Your guess (%i) is below the actual number \n', numb)
elseif numb > r
fprintf('Your guess (%i) is above the actual number \n', numb)
else
fprintf('Congratulations, you guessed the right number %d!\n', r)
end
end
댓글 수: 0
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!