I know how can I convert decimals to any other kind of bases less than 10 but could we do this without using any arrays or strings in the C language?
- get n as a input number
- get b as a base that we want to convert to that.
- print the number in b base
CodePudding user response:
solve in this way:
- get n as an input number.
- get b as a base that we want to convert to that.
- print the number in b base here is a sum.
#include <stdio.h>
int main()
{
long long int n;
int b;
long long int sum=0;
int i=1;
scanf("%lld %d",&n,&b);
while(n>0)
{
sum =(n%b)*i;
i*=10;
n/=b;
}
printf("%lld",sum);
return 0;
}