c语言程序设计公司笔试题,C语言编程笔试题(第十七套)

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));

}

分享给朋友:

亲~ 如果您有更好的答案 可在评论区发表您独到的见解。

您想查看更多的信息:

面试题

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值