65.请编写函数fun,其功能是:将两个两位数的正整数a、b合并形成一个整数放在c中。合并的方式是:将a数的十位和个位数依次放在c数的百位和个位上,b数的十位和个位数依次放在c数的十位和千位上。
例如,当a=45,b=12,调用该函数后,c=2415。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
#include <conio.h>
#include <stdio.h>
void fun (int a, int b, long *c )
{
}
main ()
{
int a, b;
long c;
clrscr ();
printf (“Input a, b;”);
scanf (“%d%d”, &a, &b);
fun (a, b, &c);
printf (“The result is : %ldn”, c);
}
66.假定输入的字符串中只包含字母和*号。请编写函数fun,它的功能是:删除字符串中所有的*号。在编写函数时,不得使用C语言提供的字符串函数。
例如,若字符串中的内容为****A*BC*DEF*G*******,删除后,字符串中的内容则应当是ABCDEFG。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
#include <stdio.h>
#include <conio.h>
void fun( char *a )
{
}
main()
{
char s[81];
printf(“Enter a string:n”);
gets(s);
fun( s );
printf(“The string after deleted:n”);
puts(s);
}
改错题:
96.下列给定程序中,函数fun的功能是:求s的值。设
12 42 62 (2k)2
b= —— × —— × —— × … × —————
1×3 3×5 5×7 (2k-1)x(2k+1)
例如,当k为10时,函数值应为1.533852。
请改正程序中的错误,使程序能输出正确的结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构!
试题程序:
#include <conio.h>
#include <stdio.h>
#include <math.h>
/********found********/
fun(int k)
{
int n;
float s,w,p,q;
n=1;
s=1.0;
while(n<=k)
{
w=2.0*n;
p=w-1.0;
q=w+1.0;
s=s*w*w/p/q;
n++;
}
/********found********/
return s
}
main( )
{
clrscr( );
printf(“%lfn”,fun(10));
}
97.下列给定程序中,函数fun的功能是:计算
S=f(-n)+f(-n+1)+…+f(0)+f(1)+f(2)+…+f(n)的值。
例如,当n为5时,函数值应为10.407143。f(x)函数定义如下:
(x+1)/(x-2) x>O
f(x)= 0 x=0或x=2
(x-1)/(x-2) x<O
请改正程序中的错误,使程序能输出正确的结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构!
试题程序:
#include <conio.h>
#include <stdio.h>
#include <math.h>
/********found********/
f(double x)
{
if(x==0.0||x==2.0)
return 0.0;
else if(x<0.0)
return (x-1)/(x-2);
else
return (x+1)/(x-2);
}
double fun(int n)
{ int i;double s=0.0,y;
for(i=-n;i<=n;i++)
{y=f(1.0*i);s+=y;}
/********found********/
return s
}
main( )
{ clrscr( );
printf(“%fn”,fun(5) );
}