更多"编写函数fun( ),它的功能是利用以下所示的简单迭代方法求方程cos"的相关试题:
[简答题]编写函数fun( ),它的功能是利用以下所示的简单迭代方法求方程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的一个实根,作为函数值返回。
程序输出结果Root=0.739085。
注意:部分源程序已存在文件test6_2.cpp中。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
文件test6_2的内容如下:
#include<conio.h>
#include<math.h>
#include<iostream.h>
float fun( )
void main( )
cout<<"Root="<<fun( )<<endl;
[简答题]编写fun( )函数,它的功能是:利用以下所示的简单迭代方法求方程cos(y)-y=0的一个实根。
yn+1=cos(yn)
迭代步骤如下:
(1)取y1初值为0.0;
(2)y0=y1,把y1的值赋给y0;
(3)y1=cos(y0),求出一个新的y1;
(4)若y0-y1的绝对值小于0.000001,则执行步骤(5),否则执行步骤(2);
(5)所求y1就是方程cos(y)-y=0的一个实根,作为函数值返回。
程序将输出结果Result=0.739085。
请勿改动main( )函数与其他函数中的任何内容,仅在函数fun( )的花括号中填入所编写的若干语句。
部分源程序给出如下。
试题程序:
#include<conio.h>
#include<math.h>
#include<stdio.h>
float fun( )
{
}
void main( )
{
FILE *out;
float cos=fun( );
printf("Result=%f/n", cos);
out=fopen("outfile.dat", "w");
fprintf(out, "%f", cos);
fclose(out);
}
[简答题]编写函数fun,其功能是:利用下面的简单迭代方法求方程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的一个实根,作为函数值返回。
程序将输出结果Root=0739086。
注意:部分源程序给出如下。
请勿改动主函数数main和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。
试题程序:
#include<conio.h>
#include<math.h>
#include<scdio.h>
double fun( )
main( )
double f=fun( );
printf("Root=%f/n",f);
[简答题]规定输入的字符串中只包含字母和*号。编写函数fun,其功能是:删除字符串中所有的*号。编写函数时,不得使用C语言提供的字符串函数。
例如,字符串中的内容为“****A*BC*DEF*G*******”,删除后,字符串中的内容应当是“ABCDEFG”。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。
试题程序:
#include<stdio.h>
void fun(char*a)
voidmain( )
char s[81];
printf("Enter a string:/n");
gets(s);
fun(s);
printf("The string after delete&/n");
puts(s);
[简答题]编写函数,isValue,它的功能是:求以下数列中满足t(K)=1的最小的k,结果由函数返回。其中数列t(n)的定义为:
t(0)=m(m为给定正整数,m<=300)
t(n+1)=t(n)/2 (当t(n)为偶数时)
或t(n+1)=3*t(n)+1(当t(n)为奇数时)
最后调用函数writeDat( )读取50个数据m,分别得出结果且把结果输出到文件out.dar中。
例如:当t=299时,函数值为117。
已知对于m<=300,结果k不超过300
部分源程序已给出。
请勿改动主函数main( )和写函数writeDat( )的内容。
#include<stdio. h>
int jsValue(int m)
main ( )
int m;
m=300;
printf ("m=%d, k-%d/n", m, jsValue (m));
writeDat ( );
writeDat ( )
FILE *in, *out;
int i,m,s;
in= fopen ( "in. dar" , "r" );
out=f open ( "out. dar" , "w" );
for (i=0; i<50; i++)
fscanf (in, "%d", &m);
s=jsValue (m);
printf( "%d/n", s );
fprintf (out, "%d/n" , s );
fclose (in);
fclose (out);
[简答题]请编写函数fun( ),函数的功能是求出二维数组周边元素之和,作为函数值返回。二维数组中的值在主函数中赋予。
例如:若二维数组中的值为
1 3 5 7 9
2 9 9 9 4
6 9 9 9 8
1 3 5 7 0
则函数值为61。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
试题程序:
#include<conio.h>
#include<stdio.h>
#define M 4
#define N 5
int fun( int a [M][N])
main( )
int aa[M][N]=1,3,5,7,9,2,9,9,9,4,
6,9,9,9,8,1,3,5,7,0;
int i, j, y;
clrscr( );
printf ("The original data is :/n ");
for(i=0; i<N;i++)
for (j=0; j<N;j++)
printf("%6d ",aa[i][j]);
printf("/n ");
y=fun(aa);
printf("/nThe sun:%d/n ",y);
printf("/n");
[简答题]请编写函数proc( ),该函数的功能是:计算n门课程的平均分,计算结果作为函数值返回。
例如,有6门课程的成绩是90.5,72,80,61.5,55,60,则函数的值为69.83。
注意:部分源程序给出如下。
请勿改动main( )函数和其他函数中的任何内容,仅在函数proc( )的花括号中填入所编写的若干语句。
试题程序:
#include<stdio.h>
float proc(float*a,int n)
{
}
void main( )
{
float score[30]={90.5,72,80,61.5,55,60},
aver;
aver=proc(score,6);
printf("/nAverage score is:%5.2f/n",aver);
}
[简答题]请编写函数fun( ),该函数的功能是:计算n门课程的平均分,计算结果作为函数值返回。
例如x有5门课程的成绩是90.5,72,80,61.5,55,则函数的值为71.80。
注意:部分源程序给出如下.
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
试题程序:
#include <stdio.h>
float fun (float *a, int n)
{
}
main ( )
{
float score[30]=(90.5,72,80,61.5,55},
aver;
aver=fun(score, 5);
printf("/nAverage score is: %5.2f
/n",aver);
}
[简答题]请编写函数fun( ),该函数的功能是:统计各年龄段的人数。N个年龄通过调用随机函数获得,并放在主函数的age数组中。要求函数把0至9岁年龄段的人数在d[0]中,把10至19岁年龄段的人数放在d[1]中,把20至29岁年龄段的人数放在 d[2]中,依次类推,把100岁(含100)以上年龄的人数都放在d[10]中。结果在主函数中输出。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
试题程序:
#include <stdio. h>
# define N 50
# define M 11
void fun(int *a, int *b)
double rnd( )
static t=29, c=217,m=1024, r=0;
r= (r*t+c)%m;
return ((double) r/m);
main ( )
int age[N], i,d[M];
for(i=0; i<N; i++)
age [i]= (int) (i15*rnd ( ));
/*产生一个随机的年龄数组*/
printf ("The original data : /n");
for(i=0; i<N; i++)
printf((i+l)%10= =07 "%4d/n":"%4d",
age[i]); /*每行输出10个数* /
printf ("/n/n");
fun (age, d);
for(i=0; i<l0; i++)
printf("%4d---%4d :%4d/n", i*l0,
i*10+9, d[i] );
printf("Over 100 : %4dkn",d[10]).;
[简答题]下列程序定义了NXN的二维数组,并在主函数中赋值。请编写函数fun( ),函数的功能是求出数组周边元素的平方和并作为函数值返回给主函数中的s。例如:若a数组中的值为
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,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;i++)
{printf("%4d",a[i][j]);}
printf("/n");
}
s=fun(a);
printf("*****THE RESULT*****/n");
printf("The sum is:%d/n",s);
}
[多项选择]编程题
下列程序定义了N×N的二维数组,并在主函数中赋值。请编写函数fun( ),函数的功能是:求出数组周边元素的平方和并作为函数值返回给主函数中的s。例如:若a 数组中的值为
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
#include
#include
#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
[简答题]编写函数fun,其功能是:求Fibonacci数列中大于t的最小的数,结果由函数返回。Fibonacci数列F(n)的定义为:
F(0)=0,F…=1
F(n)=F(n-1)+F(n-2)
例如,当t=1000时,函数值为1597。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。
试题程序:
#include<conio.h>
#include<math.h>
#include<scdio.h>
int fun(int t)
main( )
int n;
n=1000;
printf("n=%d,f=%d/n",n,fun(n));
[简答题]编写函数int fun(int lim, int aa[MAX]),该函数的功能是求出小于或等于lim的所有素数并放在aa数组中,该函数返回所求出的素数的个数。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
试题程序:
#include<conio.h>
#include<stdio.h>
#define MAX 100
int fun(int lim, int se[MAX])
main( )
int limit,i,sum;
int aa[MAX];
clrscr( );
printf("输入一个整数");
scanf("%d",&limit);
sum=fun(limit,aa);
for(i=0;i<sum;i++)
if(i%10==0&&i!=0) /*每行输出10个数*/
printf("/n");
printf("%5d ",aa[i]);
[简答题]下列程序定义了N×N的二维数组,并在主函数中赋值。请编写函数fun( ),函数的功能是:求出数组周边元素的平均值并作为函数值返回给主函数中的s。例如:若a数组中的值为
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);
}