c-moodle/homework/11965.c

30 lines
603 B
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include <stdio.h>
int x;
char ss[100005];
// 定义递归函数myint2str
void myint2str(int a, char s[], int k);
int main() {
scanf("%d", &x);
myint2str(x, ss, 0);
printf("%s", ss);
}
void myint2str(int a, char s[], int k) {
// 定义变量ki用于记录s数组中加入数位的个数
int ki = 0;
// 如果a不为0将a的末位转换成char存储到s数组中
while (a) {
s[ki++] = a % 10 + '0';
a /= 10;
}
// 将s最后一个元素赋值为'\0',表示字符串结束
s[ki] = '\0';
// 设置 k 为字符串长度
k = ki;
}