I wrote a program, but this is so buggy I guess?
I have this P4 2.6Ghz pc & 1GB Ram, I guess it's running out of memory or something.
Some numbers it will print not a prime / is a prime.
Let say primeTest(1)
it will say it's a prime
but when you do like primeTest(10)
nothing shows instead, on the bottom of the matlab (where the start menu is located), it will say "busy".
is there something i misunderstood my own program?
function primeTest(x)
n = 3;
R=rem(x,n);
while R ~= 0 & n < sqrt(x) & n < 10
n+2;
r=rem(x,n);
end
if R ~= 0
disp('Is a prime')
else
disp('Not a prime')
"John Wong" <gokoproject@gmail.com> wrote in message <h9fob7$hs7$1@fred.mathworks.com>...
> I wrote a program, but this is so buggy I guess?
> I have this P4 2.6Ghz pc & 1GB Ram, I guess it's running out of memory or something.
>
> Some numbers it will print not a prime / is a prime.
>
> Let say primeTest(1)
> it will say it's a prime
>
> but when you do like primeTest(10)
> nothing shows instead, on the bottom of the matlab (where the start menu is located), it will say "busy".
>
> is there something i misunderstood my own program?
>
>
> function primeTest(x)
> n = 3;
> R=rem(x,n);
> while R ~= 0 & n < sqrt(x) & n < 10
> n+2;
> r=rem(x,n);
> end
> if R ~= 0
> disp('Is a prime')
> else
> disp('Not a prime')
>
> end
> end
In your while loop your forget to assign n+2 to n which explains why you stay in thsi while loop and MATLAB stays busy:
replace n+2 by n = n+2
"John Wong" <gokoproject@gmail.com> wrote in message <h9fob7$hs7$1@fred.mathworks.com>...
> I wrote a program, but this is so buggy I guess?
> I have this P4 2.6Ghz pc & 1GB Ram, I guess it's running out of memory or something.
>
> Some numbers it will print not a prime / is a prime.
>
> Let say primeTest(1)
> it will say it's a prime
>
> but when you do like primeTest(10)
> nothing shows instead, on the bottom of the matlab (where the start menu is located), it will say "busy".
>
> is there something i misunderstood my own program?
>
>
> function primeTest(x)
> n = 3;
> R=rem(x,n);
> while R ~= 0 & n < sqrt(x) & n < 10
> n+2;
NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for
all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content.
Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available
via MATLAB Central.
Read the complete Terms prior to use.