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

匿名网友 匿名网友 发布于: 2015-08-30 00:00:00
阅读 277 收藏 0 点赞 0 评论 0

编程题:

5.请编写一个函数void fun(int m,int k,int xx[]),该函数的功能是:将大于整数m且紧靠m的k个素数存入xx所指的数组中。

例如,若输入:17,5,则应输出:19,23,29,31,37。

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

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

#include <conio.h>

#include <stdio.h>

void fun(int m, int k, int xx[])

{

 

}

main()

{

int m,n,zz[1000];

clrscr();

printf(“nPlease enter two integers:”);

scanf(“%d,%d”,&m,&n);

fun( m,n,zz);

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

printf(“%d “, zz[m]);

printf(“n”);

}

 

9.编写函数fun,它的功能是:根据以下公式求P的值,结果由函数值带回。m与n为两个正整数且要求m>n。

 

例如:m=12,n=8时,运行结果为495.000000。

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

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

#include <conio.h>

#include <stdio.h>

float fun( int m, int n)

{

 

}

main()

{

clrscr();

printf(“P=%fn”, fun(12,8));

}

 

改错题:

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

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

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

试题程序:

#include<conio.h>

#include<stdio.h>

 

/********found********/

void fun(long  s, long t)

{

long  s1=10;

*t = s % 10;

while ( s > 0)

{

s = s/100;

*t = s%10 * s1 + *t;

/********found********/

s1 = s1*100;

}

}

 

main()

{

long s, t;

clrscr();

printf(“nPlease enter s:”);

scanf(“%ld”, &s);

fun(s, &t);

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

}

 

 

66.下列给定程序中,fun函数的功能是:求出以下分数序列的前n项之和。

2    3    5    8    13    21

-   -   -   -   -    -

1,  2,  3,  5,  8,   13,…

和值通过函数值返回main()函数。例如,若n=5,则应输出8.391667。

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

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

试题程序:

#include <conio.h>

#include <stdio.h>

 

/********found********/

fun (int n )

{

int a=2, b=1, c, k ;

double s=0.0 ;

for ( k = 1; k <= n; k++ )

{

s = s + 1.0 * a / b ;

/********found********/

c = a;

a += b;

b += c;

}

return s;

}

 

main( )

{

int  n = 5 ;

clrscr( ) ;

printf(“nThe value of function is :%lfn”,  fun ( n ) ) ;

}

评论列表
文章目录