I keep getting the error Output argument "prime2" (and maybe others) not assigned during call to "sum_of_primes". Can someone explain why?
% This function takes an even integer greater than 2
% and expresses it as the sum of two prime integers
function [prime1, prime2] = sum_of_primes (num) %%If input is an even integer greater than 2
if (mod(num,2) == 0) && (num > 2) %%Initializing vector x to numbers from 1 to num
% any non-prime number is set to 0
for n = 1:num if (isprime(n) == true) x(n) = n; end end %%Initializing vector z as array x without the zeros
% z will then be a vector of prime numbers
z = (x(x~=0))'; z = z<num; %%Doing things and stuff
for n = 1:size(z) prime1 = z(n); if (isprime(num-prime1) == true) prime2 = num-prime1; break; end endelse disp('Please enter an integer greater than 2.')end
end
Best Answer