2015-11-01 06:30:02
阅读( 135 )
编程题:
55.请编写函数fun,该函数的功能是:将M行N列的二维数组中的数据,按行的顺序依
次放到一维数组中,一维数组中数据的个数存放在形参n所指的存储单元中。
例如,若二维数组中的数据为:,
则一维数组中的内容应是:33 33 33 33 44 44 44 44 55 55 55 55。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
#include
void fun(int (*s)[10], int *b, int *n, int mm, int nn)
{
}
main()
{
int w[10][10] = {{33,33,33,33},{44,44,44,44},{55,55,55,55}}, i, j ;
int a[100] = {0}, n = 0 ;
printf(“The matrix:\n”) ;
for(i = 0 ; i < 3 ; i++)
{
for(j = 0 ; j < 4 ; j++)
printf(“%3d”,w[i][j]) ;
printf(“\n”) ;
}
fun(w, a, &n, 3, 4) ;
printf(“The A array:\n”) ;
for(i = 0 ; i < n ; i++)
printf(“%3d”,a[i]);
printf(“\n\n”) ;
}
58.编写函数fun,它的功能是:求n以内(不包括n)同时能被3与7整除的所有自然数之和的平方根s,并作为函数值返回。
例如,若n为1000时,函数值应为s=153.909064。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
#include
#include
#include
double fun( int n)
{
}
main()
{
clrscr();
printf(“s=%f\n”, fun ( 1000) );
}
改错题:
19.下列给定程序中函数fun的功能是:从低位开始取出长整型变量s中偶数位上的数,依次构成一个新数放在t中。例如,当s中的数为7654321时,t中的数为642。
请改正程序中的错误,使它能得出正确的结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构!
试题程序:
#include
#include
/********found********/
void fun(long s,long t)
{
long s1=10;
s/=10;
*t=s%10;
/********found********/
while(s<0)
{
s=s/100;
*t=s%10*s1+*t;
s1=s1*10;
}
}
main()
{
long s,t;
clrscr();
printf(“\nPlease enter s:”);
scanf(“%ld”,&s);
fun(s,&t);
printf(“The result is:%ld\n”,t);
}
27.下列给定程序中,函数fun的功能是:根据以下公式求π值,并作为函数值返回。
例如,给指定精度的变量eps输入0.0005时,应当输出Pi=3.140578。
π 1 1 2 1 2 3 1 2 3 4
-= 1+ - + -x- + -x-x- +-x-x-x- + …
2 3 3 5 3 5 7 3 5 7 9
请改正程序中的错误,使它能得出正确结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。
试题程序:
#include
#include
#include
double fun(double eps)
{
double s,t;
int n=1;
s=0.0;
/********found********/
t=0;
/********found********/
while(t>eps)
{
s+=t;
t=(t*n)/(2*n+1);
n++;
}
return(s*2);
}
main()
{
double x;
printf(“\nPlease enter a precision: “);
scanf(“%lf”,&x);
printf(“\neps=%lf, Pi=%lf\n\n”,x,fun(x));
}
分享给朋友:
亲~ 如果您有更好的答案 可在评论区发表您独到的见解。
您想查看更多的信息:
面试题