rand but even numbers

8 次查看(过去 30 天)
stephen aboasu
stephen aboasu 2015-9-12
how do I write a script that will generate one random integer between 1 and 100, and will print whether the random integer is an even or an odd number.

回答(1 个)

Star Strider
Star Strider 2015-9-12
Two functions, randi and rem or mod are all you need. Of course you’ll also need one of the print functions such as fprintf or sprintf, but that’s obvious.

类别

Help CenterFile Exchange 中查找有关 Random Number Generation 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by