Jump to content

Welcome to Geeks to Go - Register now for FREE

Need help with your computer or device? Want to learn new tech skills? You're in the right place!
Geeks to Go is a friendly community of tech experts who can solve any problem you have. Just create a free account and post your question. Our volunteers will reply quickly and guide you through the steps. Don't let tech troubles stop you. Join Geeks to Go now and get the support you need!

How it Works Create Account
Photo

How to make this program?


  • Please log in to reply

#1
chilli

chilli

    New Member

  • Member
  • Pip
  • 4 posts
Hi guys. I want to know how to make a program that asks the user to enter a number and then displays all its factors. Thanks in advance. (I am counting on you guys!!!)
  • 0

Advertisements


#2
MaverickSidewinder

MaverickSidewinder

    Member

  • Member
  • PipPipPip
  • 257 posts
This for school?

Anyway, in what language?

You should explain yourself better
  • 0

#3
ChrisWright

ChrisWright

    Member

  • Member
  • PipPip
  • 34 posts
You really need to add details on ANY program development programs you have, or have experience with...

If none, I would advise you try to Google for it, and theres a posibility that someone has made such a program before, and made it available.

Chris
  • 0

#4
chilli

chilli

    New Member

  • Topic Starter
  • Member
  • Pip
  • 4 posts
Sorry guys!! Yes. This is for school. The language is C.
  • 0

#5
Swandog46

Swandog46

    Malware Expert

  • Member
  • PipPipPipPip
  • 1,026 posts
  • MVP

I want to know how to make a program that asks the user to enter a number and then displays all its factors.

Really hard! This problem is known to be in NP, though it is not known whether it is NP-complete (computationally infeasible). I discussed NP and NP-completeness before here:
http://www.geekstogo...howtopic=121232

Wikipedia describes a number of the standard algorithms for factorization.
http://en.wikipedia....r_factorization

None of them is very good though, keep in mind! They will work only for small enough numbers that you can solve the problem largely by brute force. Factoring very large numbers is VERY hard --- in fact, if you could find an efficient way to do it you would break most known cryptographic systems including RSA, which are used to encrypt bank data. So if you solve this problem watch your back and take all your money out of the bank! :whistling:

Hope this helps.


EDIT: I'll be more specific. If you are just trying to factor small numbers n, the obvious brute-force approach is just to iterate through all integers less than or equal to (n / 2) and test whether they divide evenly into n (i.e. in C test whether (n % i) == 0 for all i <= n/2). All the numbers that match are the divisors. Then you have to sift through those to find the prime factors, if that is what you want (or if you want all the divisors, you have them).

This algorithm will get very slow as n gets even moderately large (like > 1000 or 10000 or I dunno, it depends on your hardware).

Edited by Swandog46, 05 September 2006 - 01:54 PM.

  • 0

#6
TaNkZ101

TaNkZ101

    Member

  • Member
  • PipPipPip
  • 327 posts
would it help if you could somehow tell it to use the tricks like, if the number is even it's divisible by 2, or if the sum of the last two digits is whatever it's divisible by whatever (i forgot them lol) hmm nevermind because if a factor were to be >10 then you'd still have to use the brute force method. although i guess you could use it in specific cases if i<11, but this is probably all irrelevant, just me thinking
  • 0

#7
Hai Mac

Hai Mac

    Member

  • Member
  • PipPipPip
  • 260 posts
That's a good idea, TaNkZ101, but may be we should stopwatch it to see if it's all really worth it. For the sake of a shorter code I would stick to the brute force method :whistling:
  • 0






Similar Topics

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

As Featured On:

Microsoft Yahoo BBC MSN PC Magazine Washington Post HP