i want to find factors of any given number. i am trying in the following way..how far is it right?
Code:for(i=1; i<=num; i++) { if(num%i==0) printf("Factor = %c",i); }
i want to find factors of any given number. i am trying in the following way..how far is it right?
Code:for(i=1; i<=num; i++) { if(num%i==0) printf("Factor = %c",i); }
why do you use %c format?
All problems in computer science can be solved by another level of indirection,
except for the problem of too many layers of indirection.
– David J. Wheeler
Hey,
If u r getting ur desired results then its right else wrong. what to worry about.
S_ccess is waiting for u. Go Ahead, put u there.
Works for me approach is not good enoughIf u r getting ur desired results then its right
All problems in computer science can be solved by another level of indirection,
except for the problem of too many layers of indirection.
– David J. Wheeler
If you think about it, you only have to check for factors until sqrt(n). Beyond that point, any factors you find you already found (as long as you print them). Something like this:
Just a suggestion.Code:for(x = 1; x*x < n; x ++) { if(n % x == 0) { printf("Factor: %d\nFactor: %d\n", x, n/x); } }
dwk
Seek and ye shall find. quaere et invenies.
"Simplicity does not precede complexity, but follows it." -- Alan Perlis
"Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
"The only real mistake is the one from which we learn nothing." -- John Powell
Other boards: DaniWeb, TPS
Unofficial Wiki FAQ: cpwiki.sf.net
My website: http://dwks.theprogrammingsite.com/
Projects: codeform, xuni, atlantis, nort, etc.