简答题 C语言
题号 #2253894

下列给定程序中函数proc的功能是:取出长整型变量s 中偶数位上的数,依次构成一个新数放在t中。例如,当s中的数为123456789时,t中的数为2468。请修改程序中的错误,使它能得出正确的结果。

注意:不要改动main()函数,不得增行或删行,也不得更改程序的结构。

试题程序:

#include<stdlib.h>

#include<stdio.h>

#include<conio.h>

//****found****

void proc(long S,long t)

{  long s1=10;

   s/=l0;

   *t=s%10;

   //****found****

   while(s<0)

       {  s=s/100;

          *t=s%10*s1+*t;

          s1=s1*10:

}

}

void main()

{  long s,t;

   system("CLS");

   printf("knPlease enter s:");

   scanf("%1d",&s);

   proc(s,&t);

   printf("The result is:%1d\n",t);

    }

10.5p��n- P4 �+�体;mso-bidi-font-family:宋体'>:


   %d\n",【3】);

}

进入在线模考

参考答案

暂无

答案解析

(1)错误:void proc(long s,long t)

正确:void proc(long s,lon9*t)

(2)错误:while(s<0)

正确:while(s>0)

【解析】从主函数中实参可知,形参的第二个变量是长整型的指针变量。因此“void proc(long s,long t)”应改为“void proc(long s,long*t)”;要从低位开始取出长整型变量s中偶数位上的数,每次变量S要除以100,然后判断其是否大于0来决定是否要继续,因此“while(s<0)”应改为“while(s>0)”。

你可能感兴趣的试题

找试题 · 找答案 · 找资料 在线模考