i was just writing a program to change a decimal number to another base(2<=radix<=16).
after running the program and printing the correct answer, I encountered an error that reads : "program has stopped working" . could you please take a look at my code and find where it dangles???!!! i am really confused.
this is my code:
int decimal, radix, pow = 1, temp;
printf("enter your number and the 2 <= radix <= 16\n");
scanf("%d%d",&decimal, &radix);
temp = decimal;
for(; temp >= radix; temp /= radix)// finding the greatest exponent of radix in decimal
pow *= radix;
while(pow >= 1){
decimal -= temp * pow;
if(temp == 10)
printf("A");
else if(temp == 11)
printf("B");
else if(temp == 12)
printf("C");
else if(temp == 13)
printf("D");
else if(temp == 14)
printf("E");
else if(temp == 15)
printf("F");
else
printf("%d",temp);
pow /= radix;
temp = decimal / pow;
}
puts("");
i think the problem is because of "temp = decimal / pow" but how can I fix it??