d2jsp
Log InRegister
d2jsp Forums > Off-Topic > General Chat > Homework Help > Need Programming Help!!! > Visual Logic
12Next
Add Reply New Topic New Poll
Member
Posts: 13,618
Joined: Nov 24 2008
Gold: 14,610.00
Nov 16 2014 09:46pm
I need help with a simple program that you enter a max number and it computes all prime numbers up to the max.
I have an idea but i get lost. I can get fg if someone helps it is simple but i cant think of how to get the prime loop going
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
Nov 16 2014 09:50pm
1) post your code.
2) post your pseudocode for your algorithm
Member
Posts: 13,618
Joined: Nov 24 2008
Gold: 14,610.00
Nov 16 2014 10:00pm
I dotn have one i need to make a pseudocode for this, any type would help, I can only find pseudocodes that do prime numbers to 100 not prime numbers up to a number you enter
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
Nov 16 2014 10:09pm
Quote (Elements_Fury @ Nov 16 2014 11:00pm)
I dotn have one i need to make a pseudocode for this, any type would help, I can only find pseudocodes that do prime numbers to 100 not prime numbers up to a number you enter


then replace 100 with n. what's the problem?

have you considered what strategy you want to take?

one example is sieve of Eratosthenes. you create a list of numbers from 1 to n. then you go through all the multiples of composites and mark them off. whatever's left are the primes.


Alternatively, instead of starting with composite numbers and removing their multiples, you can just loop through each value and ask "is this number prime?" to determine if it's prime, divide by every number <= its sqrt. if anything divides evenly, it's not prime. then you move on to the next number in your list.

This post was edited by carteblanche on Nov 16 2014 10:17pm
Member
Posts: 13,618
Joined: Nov 24 2008
Gold: 14,610.00
Nov 16 2014 10:17pm
The idea i had was to start with input max of course
make a for statement
I
2 to max

Then some how in that for statement put an algorithm that finds the prime numbers in-between 2 to max, using modular
If the mod is 0 it has to be non-prime thus dont print it, if the mod is <> 0 is it prime thus print (using a if statement)

I just dont know how to fit that algorithm into the for statement, and make sure it doesn't have an error.
the program is just pseudocode not code

The first example wouldn't work because visual logic is very basic and that would be a very slow list

an example i saw someone else use had like:

input max
I (from 2 to max) - for statement
J (from 2 to i/2) - for statement inside that for statement
then he some how used i mod j to find if it was a prime and print if it was
there was another perimeter inside there but i cant remember

This post was edited by Elements_Fury on Nov 16 2014 10:23pm
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
Nov 16 2014 10:19pm
Quote (Elements_Fury @ Nov 16 2014 11:17pm)
The idea i had was to start with input max of course
make a for statement
I
2 to max

Then some how in that for statement put an algorithm that finds the prime numbers in-between 2 to max, using mod
If the mod is 0 it has to be non-prime thus dont print it, if the mod is <> 0 is it prime thus print (using a if statement)


elaborate. what are you modding?

lets say the max is 10. now list the steps of your algorithm.
Member
Posts: 13,618
Joined: Nov 24 2008
Gold: 14,610.00
Nov 16 2014 10:22pm
Quote (carteblanche @ Nov 17 2014 04:19am)
elaborate. what are you modding?

lets say the max is 10. now list the steps of your algorithm.


thats what I'm trying to figure out, I'm having a brain fart and can't think of what to put inside the for statement that will produce the prime using modular
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
Nov 16 2014 10:24pm
Quote (Elements_Fury @ Nov 16 2014 11:22pm)
thats what I'm trying to figure out, I'm having a brain fart and can't think of what to put inside the for statement that will produce the prime using modular


quit worrying about coding the loop and think about the math. write down the steps one by one. once you see the pattern, you can clean it up with a loop later.

2 3 4 5 6 7 8 9 10

when you get to # 6, what do you do? give me a list of everything you're modding it by.

do the same thing for 7

This post was edited by carteblanche on Nov 16 2014 10:25pm
Member
Posts: 13,618
Joined: Nov 24 2008
Gold: 14,610.00
Nov 16 2014 10:25pm
Quote (carteblanche @ Nov 17 2014 04:09am)
then replace 100 with n. what's the problem?

have you considered what strategy you want to take?

one example is sieve of Eratosthenes. you create a list of numbers from 1 to n. then you go through all the multiples of composites and mark them off. whatever's left are the primes.
http://upload.wikimedia.org/wikipedia/commons/b/b9/Sieve_of_Eratosthenes_animation.gif

Alternatively, instead of starting with composite numbers and removing their multiples, you can just loop through each value and ask "is this number prime?" to determine if it's prime, divide by every number <= its sqrt. if anything divides evenly, it's not prime. then you move on to the next number in your list.


I am trying to do what you explained at the bottom, How would i command it to divide by every number <= its sqrt, this is my first visual logic program so I'm not sure what the process would be in pseudocode
Member
Posts: 13,618
Joined: Nov 24 2008
Gold: 14,610.00
Nov 16 2014 10:43pm
Go Back To Homework Help Topic List
12Next
Add Reply New Topic New Poll