请在程序的下划线处填入正确的内容并把下划线删除,使程序得出正确的结果。
注意:源程序存放在考生文件夹下BLANK1.C中。
不得增行或删行,也不得更改程序的结构!
给定源程序:
#include
double fun(double e)
{int i; double s, x;
/**********found**********/
s=0; i=__1__;
x=1.0;
while(x>e){
/**********found**********/
__2__;
/**********found**********/
x=(2.0*i-1)/((__3__)*(2.0*i));
s=s+x;
}
return s;
}
main()
{double e=1e-3;
printf("\nThe result is: %f\n",fun(e));
}
解题答案:
/**********第一空**********/
s=0; i=0;
/**********第二空**********/
i++;
/**********第三空**********/
x=(2.0*i-1)/((2.0*i)*(2.0*i));
****************************************** [NextPage] 二、改错题:给定程序MODI1.C中函数 fun 的功能是:将s所指字符串的正序和反序进行连
接,形成一个新串放在t所指的数组中。
例如,当s所指字符串为:"ABCD" 时,则t所指字符串中的内容应为:"ABCDDCBA"。
请改正程序中的错误,使它能得出正确的结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构!
给定源程序:
#include
#include
/************found************/
void fun (char s, char t)
{
int i, d;
d = strlen(s);
for (i = 0; i
for (i = 0; i
/************found************/
t[2*d-1] = '\0';
}
main()
{
char s[100], t[100];
printf("\nPlease enter string S:"); scanf("%s", s);
fun(s, t);
printf("\nThe result is: %s\n", t);
}
解题答案:
/************found************/
void fun(char *s, char *t)
/************found************/
t[2*d]='\0';
******************************************
[NextPage] 三、程序题:函数fun的功能是: 将s所指字符串中除了下标为奇数、同时ASCII值也为奇数的字符之外,其余的所有字符都删除,串中剩余字符所形成的一个新串放在t所指的数组中。
例如,若s所指字符串中的内容为:"ABCDEFG12345",其中字符A的ASCII码值
虽为奇数,但所在元素的下标为偶数,因此必需删除;而字符1的ASCII码值为奇
数,所在数组中的下标也为奇数,因此不应当删除,其它依此类推。最后t所指的数组中的内容应是:"135"。
注意: 部分源程序存在文件PROG1.C中。
请勿改动主函数main和其它函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。
给定源程序:
##include
#include
void fun(char *s, char t[])
{
}
main()
{
char s[100], t[100];void NONO ();
printf("\nPlease enter string S:"); scanf("%s", s);
fun(s, t);
printf("\nThe result is: %s\n", t);
NONO();
}
void NONO ()
{/* 本函数用于打开文件,输入数据,调用函数,输出数据,关闭文件。 */
char s[100], t[100] ;
FILE *rf, *wf ;
int i ;
rf = fopen("in.dat","r");
wf = fopen("out.dat","w");
for(i = 0 ; i < 10 ; i++) {
fscanf(rf, "%s", s);
fun(s, t);
fprintf(wf, "%s\n", t);
}
fclose(rf);
fclose(wf);
}
参考答案:
void fun(char *s, char t[])
{
int i, j = 0 ;
for(i = 1 ; i < strlen(s) ; i += 2)
if(s[i] % 2) t[j++] = s[i] ;
t[j] = 0 ;
}
| 广告合作:400-664-0084 全国热线:400-664-0084 Copyright 2010 - 2017 www.my8848.com 珠峰网 粤ICP备15066211号 珠峰网 版权所有 All Rights Reserved
|