Oppgave 1 - Teori
...
- function output = functionName(input1,input2,input3)
- Ja, om du skal hente et konstant tall, eller skrive ut en velkomstbeskjed til skjermen.
- Ja, om du skal skrive ut en velkomstbeskjed.
...
Code Block | ||
---|---|---|
| ||
ans = functionName(input1,input2,input3); |
Oppgave 2 - Negativt tall
Code Block |
---|
function svar = er_negativ(tall)
if tall < 0
svar = 1;
else
svar = 0;
end
end |
Oppgave 3 - Absoluttverdi
Code Block |
---|
function tall = absolutt(tall)
if tall < 0
tall = -tall;
end
end |
Oppgave 4 - Minste tall
Code Block |
---|
function indeks = indeks_minste_element(liste)
tall = liste(1);
indeks = 1;
for i = 2:length(liste)
if tall > liste(i)
tall = liste(i);
indeks = i;
end
end
end |
Oppgave 5 - Negative tall
Code Block |
---|
function svar= negativ_tabell(liste)
indeks = indeks_minste_element(liste);
if er_negativ(liste(indeks))
svar = 1;
else
svar = 0;
end
end |
Oppgave 6 - Fakultet
Code Block |
---|
function fak = fakultet(tall)
fak = 1;
for i = 1:tall
fak = fak*i;
end
end |
Oppgave 7 - Lottogenerator
Code Block |
---|
function li = lotto
li = sparse(1,7);
for i = 1:7
li(i) = randi([1,34]);
end
end |