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); }
This is a discussion on finding factors within the C Programming forums, part of the General Programming Boards category; i want to find factors of any given number. i am trying in the following way..how far is it right? ...
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?
To be or not to be == true
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
To be or not to be == true
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.