国家二级(C语言)机试模拟试卷955
程序填空题
1.使用VC++2010打开考生文件夹下blank1中的解决方案。此解决方案的项目中包含一个源程序文件blank1.c。在此程序中,函数fun的功能是:根据形参n计算并返回阶乘n!。为避免每次阶乘都要从1开始乘起,程序中使用了静态结构体变量old保存上次计算的阶乘。每次计算时,要比较新的参数n与上次计算的阶数n,以便决定计算方法。
请在程序的下画线处填入正确的内容并把下画线删除,使程序得出正确的结果。
注意:部分源程序在文件blank1.c中。
不得增行或删行,也不得更改程序的结构!
#include
#include
#include
#pragma warning (disable:4996)
struct Ord
{
\\tint n;
\\tlong ordor;
};
long fun(int n)
{
\\tstatic struct Ord old={0,1};
\\tint i;
\\tif(n==old.n)
/**********************found***********************/
\\treturn (____(1)____);
\\tif(n>old.n)
\\t\\tfor(i=old.n+1;i<=n;i++)
\\t\\t\\told.ordor*=i;
\\telse
\\t\\tfor(i=old.n;i>n;i–)
\\t\\t\\told.ordor/=i;
/**********************found***********************/
\\told.n=____(2)____;
/**********************found***********************/
\\treturn (____(3)____);
}
main( )
{
\\tint i,n;
\\tfor(i=0;i<5;i++)
\\t{
\\t\\tn=rand( )%10;
\\t\\tprintf(\\
(1)old. ordor
(2)n
(3)old. Ordor
解析:
程序修改题
2.使用VC++2010打开考生文件夹下modi1中的解决方案。此解决方案的项目中包含一个源程序文件modi1.c。在此程序中,函数fun的功能是:将形参dt0指向的具有*n0个数据的数组中,所有不等于形参x的数据,重新存留在原数组中,并通过形参n0返回这些数据的个数。
请改正程序中的错误,使它能得出正确的结果。
注意:部分源程序在文件modi1.c中。
不要改动main函数,不得增行或删行,也不得更改程序的结构!
#include
#pragma warning (disable:4996)
void fun(int *dt0,int *n0,int x)
{
\\tint i,j;
/**********************found***********************/
\\ti=1;j=1;
do
{
/**********************found***********************/
\\t if(dt0[i]=x)
\\t {
\\t\\t dt0[j]=dt0[i];
\\t\\t j++;
\\t }
\\t i++;
}
while(i<*n0);
/**********************found***********************/
return j;
}
main( )
{
\\tint d[10]={2,5,6,7,2,4,5,2,2,6},n=10,i;
\\tfun(d,&n,2);
\\tfor(i=0;i<n;i++)
\\t\\tprintf(\\
(1)i=0;j=0;
(2)dt0[1]!=x
(3)*n0=j;
解析:
程序设计题
3.使VC++2010打开考生文件夹下prog1中的解决方案。此解决方案的项目中包含一个源程序文件prog1.c。结构体struct mpow两个成员的意义是: a为幂的底,伪幂的指数。
请编写函数fun,其功能是:计算出x所指数组中n个幂数之和并返回。
例如,当结构体数组用如此数据12,0,9,2,23,1,7,2初始化时,程序的输出结果应该是: sum=15.000000
注意:部分源程序在文件prog1.c中。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。
#include
#define N 5
struct mpow
{
\\tdouble a;
\\tint t;
};
double fun(struct mpow *x,int n)
{
}
void main( )
{
\\tvoid NONO( );
\\tstruct mpow x[N]={ 12,0,9,2,23,1,7,2 };
\\tdouble sum;
\\tsum=fun(x,4);
\\tprintf(\\
double fun(struct mpow *x,int n)
{
int i, j;
double sum =0.0;
for(i=0;i<n;i++)
{
double power= 1.0;
for(j=1;j<=x[i].t;j++)
{
power *= x[i].a;
}
sum+= power;
}
return sum; }
解析:
本文档预览:3600字符,共3306字符,源文件无水印,下载后包含无答案版和有答案版,查看完整word版点下载