栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > C++面试题库

C语言编程笔试题(第十七套)

C语言编程笔试题(第十七套)

编程题:

55.请编写函数fun,该函数的功能是:将M行N列的二维数组中的数据,按行的顺序依

次放到一维数组中,一维数组中数据的个数存放在形参n所指的存储单元中。

例如,若二维数组中的数据为:,

则一维数组中的内容应是:33 33 33 33 44 44 44 44 55 55 55 55。

注意:部分源程序给出如下。

请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。

#include <stdio.h>

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(“nn”) ;

}

 

58.编写函数fun,它的功能是:求n以内(不包括n)同时能被3与7整除的所有自然数之和的平方根s,并作为函数值返回。

例如,若n为1000时,函数值应为s=153.909064。

注意:部分源程序给出如下。

请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。

#include <conio.h>

#include <math.h>

#include <stdio.h>

double  fun( int  n)

{

}

main()

{

clrscr();

printf(“s=%fn”, fun ( 1000) );

}

 

改错题:

19.下列给定程序中函数fun的功能是:从低位开始取出长整型变量s中偶数位上的数,依次构成一个新数放在t中。例如,当s中的数为7654321时,t中的数为642。

请改正程序中的错误,使它能得出正确的结果。

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

试题程序:

#include <conio.h>

#include <stdio.h>

void fun(long s,long t)

{

long s1=10;

s/=10;

*t=s%10;

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:%ldn”,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 <conio.h>

#include <math.h>

#include <stdio.h>

double fun(double eps)

{

double s,t;

int n=1;

s=0.0;

t=0;

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=%lfnn”,x,fun(x));

}

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/265390.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号