1
0
mirror of https://github.com/renbaoshuo/202401-programming-assignments.git synced 2024-11-23 15:48:42 +00:00
202401-programming-assignments/【实践课外】10.函数1/6-3 求一个大于10的n位整数w的后n-1位的数,并作为函数值返回。.c

27 lines
322 B
C

int get_digits(int x) {
int res = 0;
while (x) {
x /= 10;
res++;
}
return res;
}
int get_pow(int x, int n) {
int res = 1;
for (int i = 0; i < n; i++) {
res *= x;
}
return res;
}
int fun(int w) {
int n = get_digits(w);
return w % get_pow(10, n - 1);
}