更多"下列给定程序中,函数fun和funx的功能是:用二分法求方程2x3-4"的相关试题:
[简答题]下列给定程序中,函数fun和funx的功能是:用二分法求方程2x3-4x2+3x-6=0的一个根,并要求绝对误差不超过0.001。
例如,若给m输入-100,n输入90,则函数求得的一个根为2.000。
请改正程序中的错误,使它能得出正确的结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构!
试题程序:
#include<sfdio.h>
#include<math.h>
double funx(double x)
[return(2*X*X*X-4*x*x+3*x-6);]
double fun(double m,double n)
/*******found********/
int ;;r=(m+n)/2;
/********found********/
while(fabs(n-m)<0.001)
ifcfunx(r)*funx(n)<0)m=r;
else n=r;
r=(m+n)/2;
return r;
main( )
double m,n,root;
printf("Enter m n:/n");
scanf("%lf%lf",&m,&n);
root=fun(m,n);
printf("root=%6.3f/n",root);
[填空题]程序MODI1.C中函数fun和funx的功能是:用二分法求方程2x3-4x2+3x-6=0的一个根,并要求绝对误差不超过0.001。
例如,若给m输入-100,给n输入90,则函数求得的一个根值为2.000。
请改正程序中的错误,使程序能输出正确的结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。
文件MODI1.C内容如下:
#include<stdio.h>
#include<math.h>
double funx(double x)
return(2*x*x*x-4*x*x+3*x-6);
double fun(double m,double n)
/***********found**********/
int r;
r=(m+n)/2;
/**********found**********/
while(fabs(n-m)<0.001)
if(funx(r)*funx(n)<0) m=r;
else n=r;
r=(m+n)/2;
return r;
void main( )
double m,n,root;
printf("Enter m n:/n");
scanf("%1f%1f",&m,&n);
root=fun(m,n);
printf("root=%6.3f/n",root);
[填空题]给定程序中已建立一个带有头结点的单向链表,在main函数中将多次调用fun函数,每调用一次fun函数,输出链表尾部结点中的数据,并释放该结点,使链表缩短。
[注意] 部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的横线上填入所编写的若干表达式或语句。
[试题源程序]
#include<stdio.h>
#include<stdlib.h>
#define N 8
typedef struct list
int data;
struct list *next;
SLIST;
void fun(SLIST *p)
SLIST *t, *s;
t=P->next;
s=p;
while(t->next!=NULL)
s=t;
/*********found**********/
t=t-> (1) ;
/**********found**********/
printf(”%d”, (2) );
s->next=NULL:
/**********found**********/
free( (3) );
SLIST *creatlist(int *a)
SLIST *h, *p, *q;
int i;
h=p=(SLIST *)malloc(sizeof(SLIST));
for(i=0; i<N; i++)
q=(SLIST *)malloc(sizeof(SLIST));
q->data=a[i];
p->next=q;
p=q;
P->next=0;
return h;
void outlist(SLIST *h)
SLIST *p;
p=h->next;
if(
[填空题]由N个有序整数组成的数列已放在一维数组中,下列给定程序函数fun的功能是:利用折半查找法查找整数m在数组中的位置。若找到,返回其下标值;否则,返回-1。
折半查找的基本算法是:每次查找前先确定数组中待查的范围low和high(low<high),然后用m与中间位置(mid)上元素的值进行比较。如果m的值大于中间位置元素的值,则下一次的查找范围落在中间位置之后的元素中;反之,下一次的查找范围落在中间位置之前的元素中,直到low>high,查找结束。
请改正程序中的错误,使它能得出正确的结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构!
试题程序:
#include<stdio.h>
#define N 10
/**********found**********/
void fun(int a[],int m)
int low=0,high=N-1,mid;
while(low<=high)
mid=(low+high)/2;
if(m<a[mid])
high=mid-1;
/********found**********/
else if(m>a[mid])
low=mid+1;
else return(mid);
return(-1);
void main( )
int i,a[N]=(-3,4,7,9,13,45,67,89,100,180),
k,m;
printf("a数组中的数据如下:");
for(i=0;i<N;i++)
printf("%d",a[i]);
printf("Enter m:");
scanf("%d",&m);
k=fun(a,m);
if(k>=0)
printf("m=%d,index=%d/n",m,k);
else printf("Not be found /n");
[简答题]给定程序中,函数fun的功能是将形参给定的字符串、整数、浮点数写到文本 文件中,再用字符方式从此文本文件中逐个读入并显示在终端屏幕上。 请在程序的下划线处填入正确的内容并把下划线删除, 使程序得出正确的结果。
注意:源程序存放在考生文件夹下的BLANK1.C中。
不得增行或删行,也不得更改程序的结构!
给定源程序:
#include
void fun(char *s, int a, double f)
{
__1__ fp;
char ch;
fp = fopen("file1.txt", "w");
fprintf(fp, "%s %d %f/n", s, a, f);
fclose(fp);
fp = fopen("file1.txt", "r");
printf("/nThe result :/n/n");
ch = fgetc(fp);
while (!feof(__2__)) {
putchar(__3__); ch = fgetc(fp); }
putchar(’/n’);
fclose(fp);
}
main( )
{ char a[10]="Hello!"; int b=12345;
double c= 98.76;
fun(a,b,c);
}
[简答题]给定程序中,函数fun的功能是将参数给定的字符串、整数、浮点数写到文本 文件中,再用字符串方式从此文本文件中逐个读入,并调用库函数atoi和atof将字符串转换成相应的整数、浮点数,然后将其显示在屏幕上。请在程序的下划线处填入正确的内容并把下划线删除, 使程序得出正确的结果。
注意:源程序存放在考生文件夹下的BLANK1.C中。不得增行或删行,也不得更改程序的结构!
给定源程序:
#include
#include
void fun(char *s, int a, double f)
{
__1__ fp;
char str[100], str1[100], str2[100];
int a1; double f1;
fp = fopen("file1.txt", "w");
fprintf(fp, "%s %d %f/n", s, a, f);
__2__ ;
fp = fopen("file1.txt", "r");
fscanf(__3__,"%s%s%s", str, str1, str2);
fclose(fp);
a1 = atoi(str1);
f1 = atof(str2);
printf("/nThe result :/n/n%s %d %f/n", str, a1, f1);
}
main( )
{ char a[10]="Hello!"; int b=12345;
double c= 98.76;
fun(a,b,c);
}
[填空题]下列给定程序中函数fun的功能是:求两个非零正整数的最大公约数,并作为函数值返回。
例如,若num1和num2分别为49和21,则输出的最大公约数为7;若num1和num2分别为27和81,则输出的最大公约数为27。
请改正程序中的错误,使它能得出正确结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构!
试题程序:
#include<stdio.h>
int fun(int a,int b)
int r,t:
if(a<b)
/*********found*********/
t=a;b=a;a=t;
r=a%b;
while(r!=0)
a=b;b=r;r=a%b;
/*********found*********/
return(a);
void main( )
int num1,hum2,a;
printf("Input num1 num2:");
scanf("%d%d",&num1,&num2);
printf("num1=%d num2=%d/n/n",num1,num2);
a=fun(num1,num2):
printf("The maximun common divisor is%d/n/n",a);
[简答题]下列给定程序中,函数fun( )的功能是计算并输出high以内的素数之和。high由主函数传给fun( )函数。
例如:若high的值为100,则函数的返回值为1060。
请改正程序中的错误,使它能得到正确结果。
[注意] 不要改动main函数,不得增行或删行,也不得更改程序的结构。
[试题源程序]
#include <conio.h>
#include <stdio.h>
#include<math.h>
int fun(int high)
int sum=0, n=0, j, yes;
while(high>=2)
yes=1;
for(j=2;j<=high/2; j++)
**********************found**********************/
ifhigh%j==0
yes=0;
break;
/**********************found**********************/
if(yes==0)
sum+=high;
n++;
high--;
return sum;
main( )
clrscr( );
printf("%d/n", fun(100));
[简答题]改错题
下列给定程序中,函数fun( )的功能是计算并输出high以内的素数之和。high由主函数传给fun( )函数。若high的值为100,则函数的值为1060。
请改正程序中的错误,使它能得到正确结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。
试题程序:
#include
#include
#include
int fun(int high)
{
int sum=0,n=0, j, yes;
while(high>=2)
{
yes = 1;
for(j=2; j<=high/2; j++)
/**********************found***********************/
ifhigh%j==0
{
yes=0;
break;
}
/**********************found***********************/
if(yes==0)
{
sum+=high;
n++;
}
high--;
}
return sum;
}
main( )
{
clrscr( );
printf("%d/n",fun(100));
}
[填空题]下列给定程序中,函数fun( )的功能是:找出一个大于给定整数m且紧随m的素数,并作为函数值返回。
请改正程序中的错误,使它能得出正确的结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构.
试题程序:
#include <conio.h>
#include <stdio.h>
int fun( int m)
int i,k;
for (i=m+1; ;i++)
for (k=2;k<i;k++)
/*************found**************/
if (i%k!=0)
break;
/*************found**************/
if (k<i)
return(i);
main( )
int n;
clrscr ( );
printf("/nPlease enter n: ");
scanf ("%d", &n);
printf ("%d/n",fun(n));
[填空题]下列给定程序中,函数fun( )的功能是:给定n个实数,输出平均值,并统计平均值以上(含平均值)的实数个数。例如, n=8时,输入193.199,195.673,195.757,196.051,196.092, 196.596,196.579,196.763,所得平均值为195.838745,在平均值以上的实数个数应为5。
请改正程序中的错误,使它能得出正确的结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。
试题程序:
#include <conio.h>
#include <stdio.h>
int fun(float x[], int n)
/***************found*******************/
iht j, c=0;float xa=0.0;
for (j=0; j<n;.j++)
xa+=x[j]/n;
printf("ave=%f/n",xa);
for (j=0; j<n;j++)
if(x[j]>=xa)
c++;
returnc;
main( )
float x[l00]= 193.199,195.673,195.757,
196.051,196.092,196.596,
196.579,196.763;
clrscr ( );
printf("%d/n",fun (x,8));
[简答题]给定程序MODI1.C中函数fun的功能是:求k!(k<13),所求阶乘的值作为函数值返回。例如:若k = 10,则应输出:3628800。
请改正程序中的错误,使它能得出正确的结果。
注意:不要改动 main 函数,不得增行或删行,也不得更改程序的结构!
给定源程序:
#include
long fun ( int k)
{
if k > 0
return (k*fun(k-1));
else if ( k=0 )
return 1L;
}
main( )
{ int k = 10 ;
printf("%d!=%ld/n", k, fun ( k )) ;
}
[简答题]改错题
下列给定程序中函数fun( )的功能是计算正整数num的各位上的数字之平方和。
例如:输入352,则输出应该是38;若输入328,则输出应该是77。
请改正程序中的错误,使它能得到正确结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。
试题程序:
#include
#include
long fun(long num)
{
/**********************found***********************/
long k=1;
do
{
k+=(num%10)*(num%10);
num/=10;
/**********************found***********************/
}while(num)
return (k);
}
main( )
{
long n;
clrscr( );
printf("/Please enter a number:");
scanf("%ld",&n);
printf("/n%ld/n",fun(n));
}
[填空题]下列给定程序中函数fun( )的功能是:计算n!。例如,给 n输入5,则输出120.000000。
请改正程序中的错误,使它能得出正确的结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。
试题程序:
#include <stdio.h>
#include <conio.h>
double fun (int n)
double result=l.0;
/*************found**************/
if n==0
return 1.0;
while (n>l&&n<170)
/*************found**************/
result *=n--
return result;
main ( )
int n;
printf ("Input N: ");
scanf ( "%d" &n);
printf ("/n/n%d!=%lf/n/n",n, fun(n));
[填空题]下列给定程序中函数fun的功能是:统计substr所指的字符串在str所指的字符串中出现的次数。
例如,若字符串为aaas 1kaaas,子字符串为as,则应输出2。
请改正程序中的错误,使它能得出正确的结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构!
试题程序:
#include<stdio.h>
int fun(char*str,char*substr)
int i,j,k,num=0;
/*********found*********/
for(i=0,str[i],i++)
for(j=i,k=0;
substr[k]==str[j];
k++,j++)
/*********found*********/
If(substr[k+1]==’/0’)
num ++;
break;
return num;
main( )
char str[80],substr[80];
printf("Input a string:");
gets(str);
printf("Input a substring:");
gets(substr);
printf("%d/n".fun(str,substr));