Friday, July 31, 2009

Factoring with C programming?

I am trying to write a C programming code to factor between 1-100. Can anyone give some hints/pointers to solve this?

Factoring with C programming?
Check out this small Javascript I made that does what you want.





http://answers.yahoo.com/question/index;...





I wouldn't use that script for large numbers because it is horribly inefficient, but for small numbers it works well enough. All you would need to do is convert it to C.
Reply:Can u please clarify the question with inputs and outputs. Are you trying to find out the factors of a given number? e.g .if input is 65 output is 5,13.
Reply:Are you sure that description is correct? You can't factor a prime by definition.
Reply:Factoring as in factorising a number?


To check if A is divisible by B, try it! If the result is an integer, then you have found a factor!!! If no factors are found, the result is prime. You only ever need check for prime factors, and only ever for factors less than or equal to the square root of the number you are checking. Refer back to your school maths textbooks for more info.





Rawlyn.





In response to your additional remarks: A prime number by it's own definition has only two factors - itself and one. Therefore factorising primes is a trivial matter, not something you need to write a program to do. Try reading my post again, all the information you need is right there.


No comments:

Post a Comment