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

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

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

编程题:

70.编写函数九n,它的功能是:计算并输出下列级数和:

 

例如,当n=10时,函数值为0.909091。

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

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

#include <conio.h>

#include <stdio.h>

double fun( int n )

{

}

main()

{

clrscr();

printf(“%fn”,fun(10));

}

 

74.学生的记录由学号和成绩组成,N名学生的数据已在主函数中放入结构体数组s中,请编写函数fun,它的功能是:把分数最低的学生数据放在h所指的数组中,注意:分数最低的学生可能不止一个,函数返回分数最低的学生的人数。

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

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

#include  <stdio.h>

#define    N  16

 

typedef   struct

{

char  num[10];

int   s;

}  STREC;

int  fun  ( STREC  *a,  STREC  *b )

{

}

main ()

{

STREC  s[N]= {{“GA05”,85}, {“GA03”,76}, {“GA02”,69}, {“GA04”,85},

{“GA01”,91}, {“GA07”,72}, {“GA08”,64}, {“GA06”, 87},

{“GA015”,85}, {“GA013”,91}, {“GA012”,64}, {“GA014”,91},

{“GA011”,91}, {“GA017”,64}, {“GA018”,64}, {“GA016”,72}};

STREC  h[N];

int  i, n;

FILE  *out;

n=fun ( s, h );

printf (“The  %d  lowest  score  :n”, n);

for (i=0;  i<n;  i++)

printf (“%s  %4dn”, h[i]. num, h[i]. s);

printf (“n”);

out=fopen (“out14.dat”, “w”);

fprintf (out, “%dn”, n);

for (i=0;  i<n;  i++)

fprintf (out, “%4dn”, h[i].s);

fclose (out );

}

 

改错题:

34.下列给定程序中函数fun的功能是:将长整型数中每一位上为奇数的数依次取出,构成一个新数放在t中。高位仍在高位,低位仍在低位。例如,当s中的数为87653142时,t中的数为7531。

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

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

试题程序:

#include <conio.h>

#include <stdio.h>

void fun(long s,long *t)

{

int  d;

long s1=1;

t = 0;

while ( s>0)

{

d = s%10;

if(d%2==0)

{

*t = d * s1 + *t;

s1*=10;

}

s/=10;

}

}

main()

{

long s,  t;

clrscr();

printf(“nPlease enter s: “);

scanf(“%ld”, &s);

fun(s, &t);

printf(“The result is: %ldn”, t);

}

 

 

36.下列给定程序中,函数fun的功能是:求三个数的最小公倍数。例如,给变量x1、x2、x3分别输入15 11 2,则输出结果应当是330。

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

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

试题程序:

#include  <stdio.h>

int fun(int  x,int  y,int  z)

{

int  j,t,n,m;

j=1;

t=m=n=1;

while(t!=0&&m!=0&&n!=0)

{

j = j+1;

t=j%x;

m=j%y;

n=j%z;

}

return j;

}

main( )

{

int  x1,x2,x3,j ;

printf(“Input x1 x2 x3:  “);

scanf(“%d%d%d”,&x1,&x2,&x3);

printf(“x1=%d, x2=%d, x3=%d n”,x1,x2,x3);

j=fun(x1,x2,x3);

printf(“The minimal common multiple is : %dn”,j);

}

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

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

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