Dear All,
I have written a code to implement an algorithm for base conversion from decimal to any base between 2 and 36 given in RG Dromey. Below is my code and I have a few questions relating to it:
#include<stdio.h>
#include<stdlib.h>
int main()
{
int newbase,zero=atoi(0),q,ndigit=0,r,ascii,i;
char newrep[100];
printf("Enter number and base(between 0 and 36) to be converted");
scanf("%d%d",&q,&newbase);
while(q!=0)
{
r=q%newbase;
ndigit+=1;
ascii=zero+r;
if(ascii>atoi(9))
{
ascii=ascii+7;
}
newrep[ndigit]=(char)ascii;
q=q/newbase;
}
for(i=ndigit;i<=1;i++)
{
printf("%d",newrep[ndigit]);
}
system("pause");
return 0;
}
1. Why is there a need for reverse conversion to characters of the ascii value after conversion before storing them in the array newrep.
2. My program hangs when I input the values of q and newbase on dev C platform. Please help!