填空题 1.  请补充函数proc(),该函数的功能是:把一个整数转换成字符串,并倒序保存在字符数组str中。
    例如,当n=12345时,str="54321"。
    注意:部分源程序如下。
    请勿改动main()函数和其他函数中的任何内容,仅在函数proc()的横线上填入所编写的若干表达式或语句。
    试题程序:
    #include<stdlib.h>
    #include<stdio.h>
    #include<conio.h>
    #define M 100
    char str[M];
    void proc(long int n)
    {
    int i=0;
    while(______)
    {
    str[i]=______;
    n/=10;
    i++;
    }
    ______;
    }
    void main()
    {
    long int n=12345;
    system("CLS");
    printf("***the origial data***\n");
    printf("n=%1d",n);
    proc(n);
    printf("\n%s",str);
    }
  • 1、
【正确答案】 1、n>0
   n%10+'0'
   str[i]='\0'    
【答案解析】 按照题目的要求将一个整数转化成字符串,需要把整数每一位上的数字变为字符。因此,第1空处填“n>0”;依次将整数从低位到高位的数字转化为字符,因此,第2空处填“n%10+'0'”。最后为新的字符串添加结束符,因此,第3空处填“str[i]='\0'”。