This code is for converting a decimal number in its equivalent in any base numeric system.
The reversed result is stored in temp.
#include <stdio.h>
#include <math.h>
int main(){
long decimal;
int b = 0,i = 0,n,j = 0;
printf("Enter Decimal Number :");
scanf("%ld",&decimal);
char temp[decimal],base[decimal];
printf("Enter Base :");
scanf("%d",&b);
for(;decimal != 0;decimal /= b){
n = decimal % b;
if(n >= 0 && n <= 9)
temp[i++] = n + 48;
else if(n >= 10)
temp[i++] = n + 55;
}
for(j = 0;i >= 0;) //Reversing temp and storing it in base
base[j++] = temp[i--];
printf("Base Equivalent : %s",temp);
printf("Base Equivalent : %s",base);
return 0;
}
The temp part need to be reversed to get the correct result, yet, temp does not get reversed and stored in base. What's wrong with my code?