Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,153,015 members, 7,817,993 topics. Date: Sunday, 05 May 2024 at 02:38 AM

Basic Programmer, Help Me Solve This Question (solved) - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / Basic Programmer, Help Me Solve This Question (solved) (2014 Views)

Common Error In Laravel #1:solved File_put_contents Failed To Open Stream / Php Programmer Help Me Out ! / Help Me Solve This Java (2) (3) (4)

(1) (Reply) (Go Down)

Basic Programmer, Help Me Solve This Question (solved) by OPEYEMIAD(m): 12:51pm On May 23, 2013
write a program to display Prime number from 1 to 1000
Re: Basic Programmer, Help Me Solve This Question (solved) by spikesC(m): 1:14pm On May 23, 2013
OPEYEMI AD: write a program to display Prime number from 1 to 1000

Language?
Re: Basic Programmer, Help Me Solve This Question (solved) by Ajibel(m): 1:31pm On May 23, 2013
spikes C:

Language?

BASIC
#i think.smh
Re: Basic Programmer, Help Me Solve This Question (solved) by spikesC(m): 1:41pm On May 23, 2013
Ajibel:

BASIC
#i think.smh

lol...naija schools want useless person embarassed
Re: Basic Programmer, Help Me Solve This Question (solved) by OPEYEMIAD(m): 1:42pm On May 23, 2013
It's Qbasic
Re: Basic Programmer, Help Me Solve This Question (solved) by spikesC(m): 1:44pm On May 23, 2013
Sadly cry

Oya make i go find that text book grin

Or can you decipher sudo codes?

If you know your syntax, you surely can
Re: Basic Programmer, Help Me Solve This Question (solved) by Ajibel(m): 1:51pm On May 23, 2013
I knew it'd be that qBasic embarassed
abeg ma guy maybe spike c can help cuz i cant but u berra on ur own start learning "correct" programming languages.
Re: Basic Programmer, Help Me Solve This Question (solved) by OPEYEMIAD(m): 2:23pm On May 23, 2013
Ajibel: I knew it'd be that qBasic embarassed
abeg ma guy maybe spike c can help cuz i cant but u berra on ur own start learning "correct" programming languages.

Guy is an Assignment to be submitted at anytime he wish to ask for it. He(i mean the lecturer) even Ask us to use BASIC To design Map of Nigeria... LOL... Programming can be fun at times. He will do that by himself not me

Quick Beginner's All-Purpose Symbolic Instruction Code just for fun Language
Re: Basic Programmer, Help Me Solve This Question (solved) by spikesC(m): 2:39pm On May 23, 2013
OPEYEMI AD:

Guy is an Assignment to be submitted at anytime he wish to ask for it. He(i mean the lecturer) even Ask us to use BASIC To design Map of Nigeria... LOL... Programming can be fun at times. He will do that by himself not me

Quick Beginner's All-Purpose Symbolic Instruction Code just for fun Language

lol...you must do it ooo. I did it in my 2nd semester, 1st year grin
Re: Basic Programmer, Help Me Solve This Question (solved) by OPEYEMIAD(m): 1:09pm On May 25, 2013
No solution yet
does that mean we don't have BASIC programmer in the house
Re: Basic Programmer, Help Me Solve This Question (solved) by spikesC(m): 3:39pm On May 25, 2013
I totally forgot about this thread. Sorry, give me today, i'll paste an answer. Am on mobile now
cool
Re: Basic Programmer, Help Me Solve This Question (solved) by wy2000(m): 5:47pm On May 25, 2013
OPEYEMI AD: write a program to display Prime number from 1 to 1000
You can easily get the solution by googling, but you will miss the lesson here.
I presume you are studying computer science?
One of the best way to learn programming is to understand the problem and break it in small solution.
EG. In your case, what is a prime no...It is a no that can *only* be divided by 1 and itself!

I will provide the algorithm, while you try and do the actual code.

So the algorithm is

Num = 1
While number is less than 1000
Do
Divide num by all the numbers between 1 and num
If any of the divisions has a remainder of zero.
Then its not a prime.
Else print the num as prime number.
Re: Basic Programmer, Help Me Solve This Question (solved) by OPEYEMIAD(m): 6:14pm On May 25, 2013
wy2000:
You can easily get the solution by googling, but you will miss the lesson here.
I presume you are studying computer science?
One of the best way to learn programming is to understand the problem and break it in small solution.
EG. In your case, what is a prime no...It is a no that can *only* be divided by 1 and itself!

I will provide the algorithm, while you try and do the actual code.

So the algorithm is

Num = 1
While number is less than 1000
Do
Divide num by all the numbers between 1 and num
If any of the divisions has a remainder of zero.
Then its not a prime.
Else print the num as prime number.

yes am studying computer science
While not write the program for me leave the Algorithm alone

from Your Algorithm you stated that Num = 1 mean while 1 is not a prime number
you said i should divide num by all the numbers between 1 and num (how am i going to write that e.g LET c = num / ?

Thanks for the Algorithm
Re: Basic Programmer, Help Me Solve This Question (solved) by wy2000(m): 6:50pm On May 25, 2013
OPEYEMI AD:
yes am studying computer science
While not write the program for me leave the Algorithm alone

from Your Algorithm you stated that Num = 1 mean while 1 is not a prime number
you said i should divide num by all the numbers between 1 and num (how am i going to write that e.g LET c = num / ?

Thanks for the Algorithm

I didnt write if because i want you to do it.
If you really want the code, you can google it. That will be a shame as a CS student.

Also Algorithm is more important in CS that the programming itself. Its language agnostic.

1 is a prime no. check this formular, its a bit technical but not for a CS student. (that is why Math is compulsory)
http://en.wikipedia.org/wiki/Formulas_for_primes

To answer you question, you need a nested loop.

eg

num = 1
While num is <= 1000
do
for i 1 to num
do
----

To explain...
1 -- can only be divided by 1 and itself (ie 1) = prime
2 -- divide by 1 and 2, (there only 2 numbers btw 1 and 2) = prime
3 -- divide by 1,2 and 3 (the number 2 cannot divide 3 without a remainder) = prime
4 -- divide by 1,2,3 and 4 (2 divides 4 without a remainder) == not prime

Do for every num...

Hard? It should be, but that you learning programming... smiley
Re: Basic Programmer, Help Me Solve This Question (solved) by spikesC(m): 7:18pm On May 25, 2013
Thats better, am on pc now but i really believe you should follow the algorithm/sudo code part.

I suggested it before.
Re: Basic Programmer, Help Me Solve This Question (solved) by OPEYEMIAD(m): 8:03pm On May 25, 2013
wy2000:

I didnt write if because i want you to do it.
If you really want the code, you can google it. That will be a shame as a CS student.

Also Algorithm is more important in CS that the programming itself. Its language agnostic.

1 is a prime no. check this formular, its a bit technical but not for a CS student. (that is why Math is compulsory)
http://en.wikipedia.org/wiki/Formulas_for_primes

To answer you question, you need a nested loop.

eg

num = 1
While num is <= 1000
do
for i 1 to num
do
----

To explain...
1 -- can only be divided by 1 and itself (ie 1) = prime
2 -- divide by 1 and 2, (there only 2 numbers btw 1 and 2) = prime
3 -- divide by 1,2 and 3 (the number 2 cannot divide 3 without a remainder) = prime
4 -- divide by 1,2,3 and 4 (2 divides 4 without a remainder) == not prime

Do for every num...

Hard? It should be, but that you learning programming... smiley

Still not get it am sorry
are you telling me that 1 is a Prime number?

When i debug the program written Above
i.e num = 1
While num is <= 1000
do (do without loop?)
for i = 1 to num
do (do what?)

this program will just display 1 TO 999 still not the Prime number

i will be very grateful if you can help me write the code

see how i display even number, Square of number from 1 TO 1000

10 CLS
20 REM the program display even number and square of number
30 FOR even = 2 TO 1000 STEP 2
40 PRINT "Even Number"; "Square"
45 PRINT "============================================"
50 PRINT even; even * even
60 NEXT even
70 END
Re: Basic Programmer, Help Me Solve This Question (solved) by wy2000(m): 8:21pm On May 25, 2013
I love the fact that you made an effort. That is how you learn.

So I will help out a bit, even though its more than 10years i have written a Basic code.

Well you will be right to say that 1 is not a prime because the definition if a prime is "those numbers GREATER than 1 that aren’t multiples of any number smaller than themselves and greater than 1;"

Cls
Dim x
Dim y
For x = 2 To 1000
For y = 2 To (x - 1)
If x Mod y = 0
Then Exit For
ElseIf y = (x - 1)
Then Print x
End If
Next y
Next x

NB: I have not tested it yet.
Re: Basic Programmer, Help Me Solve This Question (solved) by OPEYEMIAD(m): 8:34pm On May 25, 2013
wy2000: I love the fact that you made an effort. That is how you learn.

So I will help out a bit, even though its more than 10years i have written a Basic code.

Well you will be right to say that 1 is not a prime because the definition if a prime is "those numbers GREATER than 1 that aren’t multiples of any number smaller than themselves and greater than 1;"

THANK you so much
there were some syntax error in the program below

Cls
Dim x
Dim y
For x = 0 To 1000
If x = 2 Then Print 2
End If (END IF without Block IF)
For y = 2 To (x - 1)
If x Mod y = 0
Then Exit For
ElseIf y = (x - 1)(syntax error ELSE WITHOUT IF)
Then Print x
End If
Next y
Next x

Kindly correct the Program please
Re: Basic Programmer, Help Me Solve This Question (solved) by wy2000(m): 8:41pm On May 25, 2013
OPEYEMI AD:

Kindly correct the Program please

like i said before, its been a while i have done a basic programming. also my last basic program was VBasic.
You will have to find the correct syntax for IF, ELSEIF on QB. I simply used my algorithm

Cls
Dim x
Dim y
For x = 2 To 1000
For y = 2 To (x - 1)
If x Mod y = 0
Then Exit For
ElseIf y = (x - 1)(syntax error ELSE WITHOUT IF)
Then Print x
End If
Next y
Next x
Re: Basic Programmer, Help Me Solve This Question (solved) by OPEYEMIAD(m): 8:44pm On May 25, 2013
NB: I have not tested it yet.[/quote]NOTED

well Glory be to God i get it done but Can you please explain the below program step by step please
10 CLS
15 REM 1 is not a prime number
20 FOR psblprm = 2 TO 1000
30 LET prime$ = "is"
35 'Don't rush Programming can be confusing at times
40 FOR psblfctr = 2 TO psblprm -1
50 IF psblprm/psblfctr = INT(psblprm/psblfctr) THEN LET prime$ = "not"
55 REM confused? YES/NO relax
60 NEXT psblfctr
70 IF prime$ = "is" THEN PRINT psblprm
75 'Your Problem is now solve
80 NEXT psblprm
90 END
Re: Basic Programmer, Help Me Solve This Question (solved) by Tpfkakambo(m): 10:48pm On May 27, 2013
the method suggested is actually going to b slow cuz each iteration thru the list of previous numbers will
include numbers that are non primes and testing these non prime numbers will increase the processing cost.

Besides the brute force strategy of testing all previous numbers is too slow overall.

there's a faster way, uses square rooting and so on.. but even that one is still too slow in the scientifc community
for mor time critical purposes!
Re: Basic Programmer, Help Me Solve This Question (solved) by Tpfkakambo(m): 10:56pm On May 27, 2013
wy2000:
You can easily get the solution by googling, but you will miss the lesson here.
I presume you are studying computer science?
One of the best way to learn programming is to understand the problem and break it in small solution.
EG. In your case, what is a prime no...It is a no that can *only* be divided by 1 and itself!

I will provide the algorithm, while you try and do the actual code.

So the algorithm is

Num = 1
While number is less than 1000
Do
Divide num by all the numbers between 1 and num
If any of the divisions has a remainder of zero.
Then its not a prime.
Else print the num as prime number.


alternatively,
instantiate a SET to store integers (the primes)
- starting from 2, till 1000
if set is empty, store the current number in set (it is prime) . this will only happen once and will store 2.
else
run thru the contents of the set, finding the modulo of the current number for the number in the set
if the modulo is 0, continue,
else, store the number in the set ,it is prime.

after number 1000
print out the content of the set, it should contain only primes.

diff: u dont consider non primes in the modulation. saves operating cost.
one more container in memory - consumes mor ram.

(1) (Reply)

Php Gurus, Showcase Your Best Applications Here / How Do I Get Access To A Telco USSD Gateway / Do You Want To Start A Career In Cyber Security And Seem Not To Find Your Feet?

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 39
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.