Go Back   CodingForums.com > :: Computing & Sciences > Computer Programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 12-06-2011, 03:40 PM   PM User | #1
szak1592
New to the CF scene

 
Join Date: Dec 2011
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
szak1592 is an unknown quantity at this point
Unhappy 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.
szak1592 is offline   Reply With Quote
Old 12-06-2011, 06:19 PM   PM User | #2
alykins
Senior Coder

 
alykins's Avatar
 
Join Date: Apr 2011
Posts: 1,608
Thanks: 37
Thanked 183 Times in 182 Posts
alykins will become famous soon enough
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
__________________

I code C hash-tag .Net
Reference: W3C W3CWiki .Net Lib
Validate: html CSS
Debug: Chrome FireFox IE
alykins is offline   Reply With Quote
Reply

Bookmarks

Tags
codes, matlab, programming

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 09:08 PM.


Advertisement
Log in to turn off these ads.