forked from ycshu/110_Fast_Algorithm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbase_p.c
More file actions
65 lines (38 loc) · 807 Bytes
/
base_p.c
File metadata and controls
65 lines (38 loc) · 807 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include <stdio.h>
#include <stdlib.h>
void PrintBaseP(int a, int p){ // input 1個整數轉為p進位,並印出此p進位及反序
if(a < p) printf("k = %d\nj = %d\n", a, a);
else{
int i, cnt, temp, *output, size;
temp = a;
cnt = 0;
while(temp > p-1){
cnt++;
temp /= p;
}
cnt++;
size = cnt;
printf("cnt = %d\n", cnt);
output = (int*)malloc(cnt*sizeof(int));//0 ~ cnt
while(cnt > 0){
printf("put in : %d\n", a%p);
output[--cnt] = a%p;
a /= p;
}
printf("size = %d\n",sizeof(output));
printf("k = ");
for(i = 0; i < size; i++){
printf("%d", output[i]);
}
printf("\n");
printf("j = ");
for(i = size-1; i >= 0; i--){
printf("%d", output[i]);
}
printf("\n");
}
}
int main(){
base_p_1(100, 4);
return 0;
}