English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

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

2006-11-21 23:41:59 · 4 answers · asked by tbwada 1 in Computers & Internet Programming & Design

I need to factor a prime number that is appeard. For example, if the I enter a number 24, its factors are 2, 2, 2, 3.

2006-11-22 00:10:06 · update #1

I could not explain the question, so this is the original question...

In this project you'll create a program that asks the user to enter a number from 1 to 100. If the
user enters a number outside of the range, you must ask him to try again. Then you should factor
this number. For example, if the user enters 24, its factors are 2, 2, 2, 3 because 24 = 2*2*2*3.

You should only have prime numbers appearing as factors. Print out all of the factors for the
number neatly.

2006-11-22 00:54:50 · update #2

4 answers

Check out this small Javascript I made that does what you want.

http://answers.yahoo.com/question/index;_ylt=AqXiTIoJWdrNI0MSsPowBbHsy6IX?qid=20061120014001AARv611

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.

2006-11-23 07:06:21 · answer #1 · answered by Kookiemon 6 · 0 0

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.

2006-11-21 23:56:13 · answer #2 · answered by Anonymous · 0 0

Are you sure that description is correct? You can't factor a prime by definition.

2006-11-22 00:46:53 · answer #3 · answered by watsonc64 3 · 0 0

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.

2006-11-21 23:56:15 · answer #4 · answered by manoj Ransing 3 · 0 0

fedest.com, questions and answers