# Thread: finding factors

1. ## finding factors

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);
}```

2. why do you use &#37;c format?

3. Hey,
If u r getting ur desired results then its right else wrong. what to worry about.

4. If u r getting ur desired results then its right
Works for me approach is not good enough

5. 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:
Code:
```for(x = 1; x*x < n; x ++) {
if(n &#37; x == 0) {
printf("Factor: %d\nFactor: %d\n", x, n/x);
}
}```
Just a suggestion.

6. Originally Posted by javani
Code:
```for(i=1; i<=num; i++)
{
if(num%i==0)
printf("Factor = %c",i);
}```
sorry, there should be %d, not %c. But, thank you DWKS too for letting idea to minimize the iterations.

Popular pages Recent additions