c语言现在有2个数 如15 25 你要把两个数之间的数输出为char* set_wheel[] = { "15","16","17","18","19","20","21","22","23","24","25" };
时间: 2023-12-05 15:41:30 浏览: 21
以下是将两个数之间的数输出为char*的C语言代码:
```c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char **set_wheel(int start, int end) {
int size = end - start + 1; char **result = (char **)malloc(size * sizeof(char *));
for (int i = 0; i < size; i++) {
result[i] = (char *)malloc(3 * sizeof(char));
sprintf(result[i], "%d", start + i);
}
return result;
}
int main() {
int start = 15, end = 25;
char **result = set_wheel(start, end);
for (int i = 0; i < end - start + 1; i++) {
printf("%s ", result[i]);
}
printf("\n");
for (int i = 0; i < end - start + 1; i++) {
free(result[i]);
}
free(result); return 0;
}
```
输出结果为:
```
15 16 17 18 19 20 21 22 23 24 25
```
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![cpp](https://img-home.csdnimg.cn/images/20210720083646.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)