...
Code Block | ||
---|---|---|
| ||
function resultatbool = helTallisInteger(N) resultatbool = (N == round(N)); end |
b)
Code Block | ||
---|---|---|
| ||
function resultatbool = parTallisEven(N) resultatbool = (helTallisInteger(N/2)); % eller resultatbool = (mod(N,2) == 0); end |
c)
Code Block | ||
---|---|---|
| ||
function resultatbool = positivtTallisPositive(N) resultatbool = (N >= 0); end |
d)
Code Block | ||
---|---|---|
| ||
N = input('Oppgi et tall: '); if helTallisInteger(N) disp('Tallet er et heltall'); if parTallisEven(N) disp('Tallet er et partall'); else disp('Tallet er et oddetall'); end else disp('Tallet er ikke et heltall'); end if positivtTallisPositive(N) disp('Tallet er positivt'); else disp('Tallet er negativt'); end |
...
Code Block | ||
---|---|---|
| ||
function resultatbool = sammenliknecompare(A, B) resultatbool = (~(A > B) && ~(A < B)); end % Mange veier til rom! |