试求下列函数值及其主值:
请帮忙给出正确答案和分析,谢谢!
第1题
a=0 1 2 7 9
1 11 21 5 5
2 21 6 11 1
9 7 9 10 2
5 4 1 4 1
则返回主程序后s的值应为310。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
试题程序:
include<stdio.h>
include<conio.h>
include<stdlib.h>
define N 5
int fun (int w[][N])
{
}
main()
{
int a[N)[N]={0,1,2,7,9,1,1l,2l,5,5,2, 21,6,11,1,9,7,9,10,2,5,4,1,4,1};
int i,j;
int S;
clrscr( );
printf("*****The array***+*\n");
for (i=0; i<N; i++)
{for(j=0;j<N;i++)
{printf(“%4d”,a[i][j]);}
printf("\n");
}
s=fun(a);
printf(“*****THE RESULT*****\n”);
printf("The sum is:%d\n",s);
}
第2题
a= 0 1 2 7 9
1 9 7 4 5
2 3 8 3 1
4 5 6 8 2
5 9 1 4 1
则返回土程序后s的值应为3.375。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的仟何内容,仅在函数fun的花括号中填入所编写的若干语句。
试题程序:
include <stdio.h>
include<conio.h>
include<stdlib.h>
define N 5
double fun (int w[] [N])
{
}
main()
{
int a[N] [N]={0,1,2,7,9,1,9,7,4,5,2,
3,8,3,1,4,5,6,8,2,5,9,1,4,1};
int i, j;
double s;
clrscr();
printf("*****The array*****\n ");
for (i=0; i<N; i++)
{ for (j=0;j<N;i++)
{printf("%4d ",a[i] [j]);}
printf("\n ");
}
s=fun(a);
printf("*****THE RESULT*****\n ");
printf("The sum is : %lf\n ",s);
}
第3题
0 1 2 7 9
1 11 21 5 5
2 21 6 11 1
9 7 9 10 2
5 4 1 4 1
则返回主程序后s的值应为310。
[注意] 部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
[试题源程序]
include <stdio.h>
include <conio.h>
include <stdlib.h>
define N 5
int fun(int w[][N])
{
}
main()
{
int a[N][N]={0, 1, 2, 7, 9, 1, 11, 21, 5, 5, 2, 21, 6, 11, 1, 9, 7, 9, 10, 2, 5, 4, 1, 4, 1};
int i, j;
int s;
clrscr()
printf("*****The array*****\n");
for(i=0; i<N; i++)
{
for(j=0; j<N; j++)
{
printf("%4d", a[i][j]);
}
printf("\n');
}
s=fun(a);
printf("*****THE RESULT*****\n");
printf("The sum is: %d\n", s);
}
第4题
请改正程序中的错误,使它能得出正确的结果。
注意;不要改动main函数,不得增行或删行,也不得更改程序的结构。
试题程序:
include<stdio.h>
include <conio.h>
include <string.h>
char *fun(char *s,char *t)
{
char *p,*r,*a;
/*************found**************/
a=Null;
while(*s)
{ p=s;r=t;
while(*r)
/*************found**************/
if(r= =p) {r++;p++;}
else break;
if(*r=='\0') a=s;
s++;
}
return a;
}
main()
{char s[100],t[100],,*p;
clrscr();
printf("\nPlease enter string S: ");
scanf("%s",s);
printf("\nPlease enter substring t: ");
scanf("%s",t);
p=fun(S,t);
if(p) printf("\nThe result is:%s\n",p);
else printf("\nNot found!\n ");
}
第5题
第6题
2/1,3/2,5/3,8/5,13/8,21/13,…
其值通过函数值返回main()函数。例如,若输入n=5,则应输出8.391667。
[注意] 部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的横线上填入所编写的若干表达式或语句。
[试题源程序]
include<stdio.h>
include<conio.h>
double fun(int n)
{
int a=2, b=1, c, k;
double (1) ;
for(k=1; k<=n; k++)
{
s=s+1.0 *a/b;
c=a; a+= (2) ; b=c;
}
return(d);
}
main()
{
int n=5;
printf("\nThe value of function is: %1f\n", (3) );
}
第7题
cos(x)-x=0的一个实根。
xn+1=cos(xn)
迭代步骤如下:
(1)取x1初值为0.0。
(2)x0=x1,把x1的值赋给x0。
(3)x1=cos(x0),求出一个新的x1。
(4)若x0-x1的绝对值小于0.000001,执行步骤(5),否则执行步骤(2)。
(5)所求x1就是方程cos(x)-x=0的一个实根,作为函数值返回。
请编写函数countValue()实现程序要求,最后调用函数writeDAT()把结果输出到文件out41.dar中。
注意:部分源程序已给出。
请勿改动主函数main()和写函数writeDAT()的内容。
试题程序:
include<conio.h>
include<math.h>
include<stdio.h>
float countvalue( )
{
main ( )
{
clrscr( );
printf("实根=%f\n",countValue( ));
printf("%f\n",cos(countValue( ))countValue( ));
writeDAT( );
writeDAT( )
{
FILE *wf;
wf=fopen("out41.dat","w");
fprintf(wf,"%fln",countValue(
fclose(wf);
}
第8题
第9题
A、若目标函数的海森矩阵H(X)对应的行列式的顺序主子式的值都小于零,则此海森矩阵H(X)为正定矩阵
B、牛顿法寻优时的搜索方向是向量表示的方向
C、利用复合形法进行优化设计时,每一轮迭代中求出的映射点只要满足可行性条件就可以作为一个寻优点
D、机械优化设计中的可行域必须是一个有界的闭域。
第10题
下列给定程序中,函数proc()的功能是:求S的值。
例如,当n为100时,函数的值应为1.566893。
请改正程序中的错误,使它能得出正确的结果。
注意:不要改动main()函数,不得增行或删行,也不得更改程序的结构。
试题程序:
【我提交的答案】:float procint i=1;
【参考答案分析】:
(1)错误:proc(int n)
正确:double proc(int k)
(2)错误:return sum
正确:return sum;
【解析】由主函数中的函数调用及函数proc()中的re-turn语句可知,函数proc()的返回值类型应为double型,因此“proc(int k)”前面应加上double;根据C语言的语法规则,每一条语句都必须以分号结束,因此语句“return s”后应加上分号。
错误不止两处。。还有函数里面的循环结构有问题。会一直循环下去,无法得出结果
为了保护您的账号安全,请在“上学吧”公众号进行验证,点击“官网服务”-“账号验证”后输入验证码“”完成验证,验证成功后方可继续查看答案!