CS 2734
Computer Organization II
#include <stdio.h>
void writebase(int, int);
char *D[] =
{"0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f"};
void main()
{
int N, B;
printf("Enter N and B:");
scanf("%d %d", &N, &B);
writebase(N, B);
printf("\n");
}
void writebase(int N, int B)
{
printf("Call Base with N and B = %d %d\n", N, B);
if (N != 0) {
writebase(N/B, B);
printf("%s", D[N%B]);
}
}
Along with sample output:
Enter values for N and B:54790143
16
The values of N and B are: 54790143 16
Call Base with N and B = 54790143 16
Call Base with N and B = 3424383 16
Call Base with N and B = 214023 16
Call Base with N and B = 13376 16
Call Base with N and B = 836 16
Call Base with N and B = 52 16
Call Base with N and B = 3 16
Call Base with N and B = 0 16
34407ff
For checkoff: