...
Code Block | ||
---|---|---|
| ||
function resultbool = wholeNumberisInteger(tallAN) resultbool = (tallAN == round(tallAN)); end |
b)
Code Block | ||
---|---|---|
| ||
function resultbool = evenNumberisEven(tallAN) resultbool = (wholeNumberisInteger(tallAN/2)); % eller resultbool = (mod(tallAN,2) == 0); end |
c)
Code Block | ||
---|---|---|
| ||
function resultbool = posNumberisPositive(tallAN) resultbool = (tallAN >= 0); end |
d)
Code Block | ||
---|---|---|
| ||
function myNumbers tallAN = input('GiveOppgi meet a numbertall: '); if isInteger(wholeNumber(tallAN)) disp('Tallet er et heltall'); if evenNumberisEven(tallAN) disp('Tallet er et partall'); else disp('Tallet er et oddetall'); end else disp('Tallet er ikke et heltall'); end if posNumberisPositive(tallAN) disp('Tallet er positivt'); else disp('Tallet er negativt'); end end |
e)
Code Block | ||
---|---|---|
| ||
function resultbool = compareNumberscompare(tallAA, tallBB) resultbool = (~(tallAA > tallBB) && ~(tallAA < tallBB)); end % Mange veier til rom! |