...
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 bool = isPositive(N) bool = (N >= 0); end |
d)
Code Block | ||
---|---|---|
| ||
N = input('Oppgi et tall: '); if isInteger(N) disp('Tallet er et heltall'); if isEven(N) disp('Tallet er et partall'); else disp('Tallet er et oddetall'); end else disp('Tallet er ikke et heltall'); end if isPositive(N) disp('Tallet er positivt'); else |
...
disp('Tallet er negativt');
end
|
e)
Code Block | ||
---|---|---|
| ||
function bool = compare(A, B)
bool = (~(A > B) && ~(A < B));
end
% Mange veier til rom! |