modi19.c

来自「c题库」· C语言 代码 · 共 37 行

C
37
字号
/*
下列给定程序中函数fun的功能是:从低位开始取出长整型变量s中偶数位上的数,依次构成一个新数放在t中。例如,当s中的数为7654321时,t中的数为642。
请改正程序中的错误,使它能得出正确的结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。
*/

#include <conio.h>
#include <stdio.h>
/**********found************/
void fun(long s,long t)
{
	long sl=10;
	s/=10;
	*t=s%10;
/**********found************/
	while(s<0)
	{
		s=s/100;
		*t=s%10*sl+*t;
		sl=sl*10;
	}
}

main()
{
	long s,t;
	clrscr();
	printf("\nPlease enter s:");scanf("%d",&s);
	fun(s,&t);
	printf("The result is :%ld\n",t);
}

/*
答案:
 void fun(long s,long t) 改为 void fun(long s,long *t)
 while(s<0)改为while(s>0)   
*/

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?