Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.

# Thread: MATLAB code to display prime numbers?

1. ## MATLAB code to display prime numbers?

Can you guys please help me with a MATLAB code, I need a simple program to display the prime numbers between 1 and 100. Please help as I am new to programming and I have to do it as an assignment.

• it has been a while since I have done MATLAB (and I did not do a whole lot in it but I will help you with the logic flow so you can figure it out) You cannot post questions on "how do I do this" for assignments, but you can ask for help on why things are not working... this pseudo code may help you
Code:
```int[] myNums = new int[100]
i=1
totalprime =0
while (i<=100){
bool eval = true
cnt = 0
while(eval = true){
for(int y=1; y<=i; y++)
if(i%y != 0) eval = false
else cnt++
if (y==i) eval false
}
if(cnt == 2) myNums[totalprime] = i
i++
}```
i think that logic flow is correct... take a look at it and tell me if you can figure out what it is doing... a key to doing this is going to be modulus

•

1. ###### What is a matlab code to find prime numbers but not using the primes function? - Yahoo UK &amp; Ireland Answers
03-21-2014, 05:20 AM