check this code . if it works correctly ? reverse the ans and you will find the no converted in target base.(ignore extra 0's)
#include <stdio.h> #include <stdlib.h> #include <string.h> #define MAX 10 int main() { int i; int b1,b2; char no1[MAX] = "",no2[MAX] = ""; int *result = (int *) calloc (sizeof(int),20); int temp; int cur_mult1 = 1,cur_mult2 = 1; int curr_10 = 1; int len; int rem = 0; result = result + 10; printf("\n Enter base and no and target base"); scanf("%d %s %d",&b1,no1,&b2); len = strlen (no1); for (i=0; i< len - 1; i++) { cur_mult1 *= b1; cur_mult2 *= b2; if (no1[i] >= 0x40) no1[i] = no1[i] - 0x40 + 9; no1[i] -= 0x30; } no1[i] -= 0x30; rem = i = 0; while (i < len) { temp = no1[i] *cur_mult1; temp += rem; result[i] = temp / cur_mult2; rem = temp % cur_mult2; cur_mult1 /= b1; cur_mult2 /= b2; i++; } i--; result[i] += rem; temp = 1; while ( i >= -3) { temp = result[i]/b2; result[i] %= b2; result[i-1] += temp; if(result[i] <10) printf("%c",result[i]+0x30); else printf("%c",result[i]+0x40-9); i--; } return 0; } On Sun, Aug 29, 2010 at 11:16 PM, luckyzoner <luckyzo...@gmail.com> wrote: > @Rahul : I know that u are using table of base b2 in base b1 and then > dividing the number using the table ...but the real problem is to code > it > > -- > You received this message because you are subscribed to the Google Groups > "Algorithm Geeks" group. > To post to this group, send email to algoge...@googlegroups.com. > To unsubscribe from this group, send email to > algogeeks+unsubscr...@googlegroups.com<algogeeks%2bunsubscr...@googlegroups.com> > . > For more options, visit this group at > http://groups.google.com/group/algogeeks?hl=en. > > -- Regards, Rahul Patil -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.