Please it's tough solving simple probs in coding. Could someone tell me how to know the algorithm required to solve a problem. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Please it's tough solving simple probs in coding. Could someone tell me how to know the algorithm required to solve a problem.

for example. write a code to solve the first 10 Prime numbers... I have gone through some part of the language course(JavaScript) here but the problem is putting things together to provide a solution... Is there anyway to learn this skill?

31st Dec 2017, 6:57 AM
Sammy
Sammy - avatar
6 Answers
+ 6
@Gordie, that was some awesome explanation , it ll help me too
31st Dec 2017, 9:42 AM
Morpheus
Morpheus - avatar
+ 5
@Gordie , why functional at later stages and can u tell something more about imperative type
31st Dec 2017, 9:45 AM
Morpheus
Morpheus - avatar
+ 3
ok so break it down. tell your program what a prime number is/ how to determine if a number is prime. Also we are going to iterate over some numbers and check to see if they meet our rule for what a prime number is. then we will have it return or print or add the numbers to an array or some other data struct maybe even sort prime and not prime into diff places. It is really just thinking about all possible outcomes and how to reach them. An algorithm is just the rules you set to reach your objective.
31st Dec 2017, 7:13 AM
emmey
emmey - avatar
+ 2
First of all this is an excelent way to get these skills, practicing code with exercises. For the problem try to separate the functions, maybe one can count from 2 to n numbers. Another one can eval the division (or remainder) of a p number and the n numbers. And some more. When you get all this small functions you can create a big function, think always that the bucle is the most important part to solve it
31st Dec 2017, 7:07 AM
Sebastián Zapata
Sebastián Zapata - avatar
+ 2
thanks everyone and thank you so much @Gordie( you shed enough light to the question asked) but pls what did you mean by sqrt(m)...and could you shed more light on imperative, functional and object oriented.... You explanation was really good.
31st Dec 2017, 1:20 PM
Sammy
Sammy - avatar
+ 1
okay thanks a lot Gordie you've been helpful
31st Dec 2017, 1:46 PM
Sammy
Sammy - avatar