例如,若N=3,有下列矩阵:
1 2 3
4 5 6
7 8 9
计算结果为
7 4 1
8 5 2
9 6 3
请在程序的下划线处填入正确的内容并把下划线删除,使程序得出正确的结 果。
注意:源程序存放在考生文件夹的BLANK1.C中。
不得增行或删行,也不得更改程序的结构!
给定源程序:
#include
#define N 4
void fun(int (*t)[N])
{ int j ,r[N];
for(j=0; j
for(j=0; j
/**********found**********/
t[0][N-j-1]=t[j][___1___ ];
for(j=0; j
t[j][0]=t[N-1][j];
/**********found**********/
for(j=N-1; j>=0;___2___ )
t[N-1][N-1-j]=t[j][N-1];
for(j=N-1; j>=0; j--)
/**********found**********/
t[j][N-1]=r[___3___];
}
main()
{ int t[][N]={21,12,13,24,25,16,47,38,29,11,32,54,42,21,33,10}, i, j;
printf("\nThe original array:\n");
for(i=0; i
{ for(j=0; j
}
fun(t);
printf("\nThe result is:\n");
for(i=0; i
{ for(j=0; j
}
}
解题答案:
/**********found**********/
t[0][N-j-1]=t[j][0];
/**********found**********/
for(j=N-1; j>=0;j--)
/**********found**********/
t[j][N-1]=r[j];
****************************************** [NextPage] 二、改错题:给定程序MODI1.C中函数 fun 的功能是:计算
S = f(-n) + f(-n+1) +…+ f(0) + f(1) + f(2) +…+ f(n)
的值。例如,当n为5时,函数值应为:10.407143。f(x)函数定义如下:
┌(x+1)/(x-2) x>0 且 x≠2
f(x) = ┤0 x=0 或 x=2
└(x-1)/(x-2) x<0
请改正程序中的错误,使程序能输出正确的结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构!
给定源程序:
#include
#include
/************found************/
f( double x)
{
if (x == 0.0 || x == 2.0)
return 0.0;
else if (x < 0.0)
return (x -1)/(x-2);
else
return (x +1)/(x-2);
}
double fun( int n )
{ int i; double s=0.0, y;
for (i= -n; i<=n; i++)
{y=f(1.0*i); s += y;}
/************found************/
return s
}
main ( )
{
printf("%f\n", fun(5) );
}
解题答案:
/************found************/
double f(double x)
/************found************/
return s;
******************************************
[NextPage] 三、程序题:编写函数fun,它的功能是计算: s作为函数值返回。 在C语言中可调用log ( n )函数求ln (n)。log函数的引用说明是: double log(double x)。 例如,若m的值为: 20,fun函数值为: 6.506583。
注意: 部分源程序在文件PROG1.C中。
请勿改动主函数main和其它函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。
给定源程序:
#include
#include
double fun(int m)
{
}
main()
{
void NONO ();
printf("%f\n", fun(20));
NONO();
}
void NONO ()
{/* 本函数用于打开文件,输入数据,调用函数,输出数据,关闭文件。 */
FILE *fp, *wf ;
int i, n ;
double s ;
fp = fopen("in.dat","r");
wf = fopen("out.dat","w");
for(i = 0 ; i < 10 ; i++) {
fscanf(fp, "%d", &n);
s = fun(n);
fprintf(wf, "%f\n", s);
}
fclose(fp);
fclose(wf);
}
参考答案:
double fun( int m )
{
double s = 0.0 ;
int i ;
for(i = 1 ; i <= m ; i++) s += log(1.0 * i) ;
s = sqrt(s) ;
return s ;
}
| 广告合作:400-664-0084 全国热线:400-664-0084 Copyright 2010 - 2017 www.my8848.com 珠峰网 粤ICP备15066211号 珠峰网 版权所有 All Rights Reserved
|