-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprintNum.c
36 lines (31 loc) · 816 Bytes
/
printNum.c
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
#include <stdio.h>
#include <math.h>
void printNum(char* origin, int base);
int main(){
int time;
char input[10];
int base;
scanf("%d", &time);
scanf("%d", &base);
for(int count = 0; count < time; count++){
scanf("%s", input);
printNum(input, base);
}
return 0;
}
void printNum(char * origin, int base){
int length = 0;
while(origin[length] != '\0'){
length++;
}
int result = 0;
for(int count = 0; count < length; count++){
result += (int) pow(base, length - count - 1) * (origin[count] - '0');
}
printf("%d ", result);
int result_reverse = 0;
for(int count = length - 1; count >= 0; count--){
result_reverse += (int) pow(base, count) * (origin[count] - '0');
}
printf("%d\n", result_reverse);
}