Any base to any base conversion in c.
#include<stdio.h>
void convert(int d, int b);
int main()
{
int num,base;
printf("Enter a number you want to convert : ");
scanf("%d",&num);
printf("Enter a base you want to convert : ");
scanf("%d",&base);
printf("\n\t Your Required answer is :");
convert(num,base);
return 0;
}
void convert(int d, int b)
{
int rem, i=0;
char ans[100];
while (d > 0)
{
rem = d % b;
if (rem < 10)
{
ans[i] = '0' + rem;
}
else
{
ans[i] = 'A' + (rem - 10);
}
d = d / b;
i++;
}
while (i--)
{
printf("%c",ans[i]);
}
printf("\n");
}
0 Comments