#include #include #include #include

<stdio.h> <conio.h> <math.h> <string.h>

void main() { long int i, j, ib, ob, a[35], temp, length, decimal, remainder[35], digits; char num[35]; decimal = 0; printf("\nenter input base (max base 35): "); scanf("%d", &ib); printf("\nenter a number with digits 0-z: "); scanf("%s", &num); printf("\nenter output base (max base 35): "); scanf("%d", &ob); length = strlen(num); for(i=0; i<length; i++) { if(int(num[i]) < 58) { a[i] = int(num[i] - 48); } if(int(num[i]) > 96) { a[i] = int(num[i] - 87); }

}

for(i=0, j=length-1; i<length/2; i++, j--) { temp = a[i]; a[i] = a[j]; a[j] = temp; } for(i=0; i<length; i++) { decimal += (a[i] * pow(ib, i)); } temp = decimal; digits = 0; while(temp != 0) { remainder[digits] = temp % ob; temp /= ob; digits++; } for(i=0, j=digits-1; i<digits/2; i++, j--)

{ temp = remainder[i]; remainder[i] = remainder[j]; remainder[j] = temp;

}

printf("\n(%s)%d = (", num, ib); for(i=0; i<digits; i++) { if(remainder[i] <10) { printf("%d", remainder[i]); } if(remainder[i] > 9) { printf("%c", remainder[i]+87); } printf(")%d", ob); } getch();

}

Sign up to vote on this title
UsefulNot useful