Versions Compared

Key

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

...

Eventuelt kan den lages litt enklere ved hjelp av matlabs strfind() funksjon.

DEL 2

a) 

Code Block
function a = isDevisable(a,b)
    a = ~mod(a,b);
end

b)

Code Block
function res = prime(a)
res = 1;
for b = 2:a-1
    if isDevisable(a,b)
        res = 0;
        break;
    end
end
end
function a = isDevisable(a,b)
    a = ~mod(a,b);
end

c)

Code Block
function res = prime(a)
res = 1;
if isDevisable(a,2)
    res = 0;
    return;
end
for b = 3:ceil(sqrt(a)) 
    if isDevisable(a,(2*b+1))
        res = 0;
        break;
    end
end
end