问题 填空题

请补充函数fun(),该函数的功能是:把一个整数转换成字符串,并倒序保存在字符数组str中。例如:当n=13572468时,str=-“86427531”。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的横线上填入所编写的若干表达式或语句。
试题程序:
#include <stdio.h>
#include <conio.h>
#define N 80
char str[N];
void fun(long int n)

int i=0;
while( 【1】 )

str[i]= 【2】
n/=10;
i++;

【3】

main()

long int n=13572468;
clrscr();
printf("*** the origial data ***\n");
printf("n=%ld",n);
fun(n);
printf("\n%s",str);

答案

参考答案:【1】n>0 【2】n%10+’0’ 【3】str[i]=’0’

解析:填空1:while循环的执行条件是n>0,当n等于0时,说明已经将整数的各位数字都转换为数字字符并存入字符串中了。填空2:n对10求余,得到整数n的个位数字,在加上字符乃,的ASCII码,得到对应的数字字符,并存入字符串 str中。填空3:将整数转换为字符串并倒序存放入字符数组str中后,还要在str最后加上字符串结束标记符’\0’。

单项选择题
单项选择题