设为首页 加入收藏

TOP

C语言编程笔试题(第二十七套)
2014-11-24 01:20:15 来源: 作者: 【 】 浏览:6
Tags:语言编程 试题 第二十七

编程题:


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


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


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


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


#include


#include


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

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


printf(“\n”);


}



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



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


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


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


#include


#include


float fun( int m, int n)


{



}


main()


{


clrscr();


printf(“P=%f\n”, fun(12,8));


}



改错题:


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


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


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


试题程序:


#include


#include



/********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: %ld\n”, t);


}




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


2 3 5 8 13 21


- - - - - -


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


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


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


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


试题程序:


#include


#include



/********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 :%lf\n”, fun ( n ) ) ;


}


】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇C语言编程笔试题(第二十六套) 下一篇C语言编程笔试题(第二十八套)

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: