So I've been trying to do this but I just can't think of a solution for this. I've got this bit of code but it outputs it backwards(if the answer is 11110 I get 01111):
#include <stdio.h>
int base(int n)
{
if(n==0)
return 0;
else
{
printf("%d",n%2);
}
return base(n/2);
}
int main() {
int n;
scanf("%d",&n);
base(n);
return 0;
}
Is there any trick for this problem or do I need to analyze this deeper?