Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Oppgave 5 - Minste tall

Code Block
function tall = minste_element(tall1, tall2)
	if tall1 < tall2
		tall = tall1;
	else
		tall = tall2;
	end
end

Oppgave 6 - Minste tall i liste

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 7 - Negative tall i tabell

...

Code Block
function li = lotto
li = sparse(1,7);
	for i = 1:7
        li(i) = randi([1,34]);
	end
end

Oppgave 13 - Sum av tall

 

Code Block
function kontroll
    n = 0;
    x = 0;
    while x < 500
        n = n + 1;
        x = sumAvTall(n);
    end
fprintf('%d is the smallest number whose sum of preceeding numbers and itself is larger than 500', n);
end
function svar = sumAvTall(n)
    sum = 0;
    for i = 1:n
        sum = sum + i;
    end
    svar = sum;
end

Oppgave 14 - Vårt første lille program (skript)

...