# Thread: Recursive print every time...

1. ## Recursive print every time...

I am writing a recursive function to print all the divisor's of a number including 1 and itself.

I am using a function
Code:
`print_recur(int number)`
and inside that I am using
Code:
`number % (number - 1)`
how can i get it to print out iff a number is divisible and just skip the ones that arent.

It will end up printing for 10: 10, 5, 2, 1 2. Code:
```void print_all_divisor(int number) {
int divis;
if (number <=0) return 0;
if ((number%(number-1)) == 0)
{ divis = number-1;
printf("%d", divis);
return print_all_divisor(number-1);
}
if((number%(number-1)) != 0)
return print_all_divisor(number-1);```
When I do this it prints only the number 1, can anyone help w/ that? Code:
```#include <stdio.h>
void divisor(int n,int i)
{
if(i<=n)
{
if(n&#37;i==0)
printf("%d ",n/i);
divisor(n,i+1);
}
}
void print_recur(int n)
{
divisor(n,1);
}

int main()
{
int n=10;
print_recur(n);
return 0;
}``` 4. Or even this one?

Code:
```#include <stdio.h>
void print_recur(int n)
{
static int i=1;
if(i<=n)
{
if(n&#37;i==0)
printf("%d ",n/i);
i++;
print_recur(n);
}
else
i=1;

}

int main()
{
int n=10;
print_recur(n);
return 0;
}``` 5. No number will will ever be divided by its one-lesser other than 2 (1).
Without using loops or statics, I don't think this can be done with only a single parameter recursion function. If you're implementing this for pedantic reasons, you may want to take a look at the gcd algo (Greatest Common Divisor) as its generally a good starting point for learning recursion. 6. There you go Chotta man i owe you a big one thanks a lot Popular pages Recent additions 