更多"下列给定程序中,函数fun和funx的功能是:用二分法求方程2x3-4"的相关试题:
[填空题]给定程序中已建立一个带有头结点的单向链表,在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(
[简答题]下列给定程序中,函数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的功能是将形参给定的字符串、整数、浮点数写到文本 文件中,再用字符方式从此文本文件中逐个读入并显示在终端屏幕上。 请在程序的下划线处填入正确的内容并把下划线删除, 使程序得出正确的结果。
注意:源程序存放在考生文件夹下的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的功能是根据形参i的值返回某个函数的值。当调用正确时, 程序输出: x1=5.000000, x2=3.000000, x1*x1+x1*x2=40.000000 请在程序的下划线处填入正确的内容并把下划线删除, 使程序得出正确的结果。 注意:源程序存放在考生文件夹下的BLANK1.C中。不得增行或删行,也不得更改程序的结构! 给定源程序: #include double f1(double x) { return x*x; } double f2(double x, double y) { return x*y; } __1__ fun(int i, double x, double y) { if (i==1) return __2__(x); else return __3__(x, y); } main( ) { double x1=5, x2=3, r; r = fun(1, x1, x2); r += fun(2, x1, x2); printf("/nx1=%f, x2=%f, x1*x1+x1*x2=%f/n/n",x1, x2, r); }
[简答题]给定程序中,函数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);
}
[简答题]给定程序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的功能是:统计substr所指的字符串在str所指的字符串中出现的次数。
例如,若字符串为aass 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 substfing: ");
gets(substr);
printf("%d/n", fun(str, substr));
}
[填空题]下列给定程序中函数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的功能是:将一个由八进制数字字符组成的字符串转换为与其值相等的十进制整数。规定输入的字符串最多只能包含5位八进制数字字符。
例如,若输入:77777,则输出将是:32767。
请改正程序中的错误,使它能得到正确结果。
[注意] 不要改动main函数,不得增行或删行,也不得更改程序的结构。
[试题源程序]
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int fun(char *p)
int n;
/**********found**********/
n=*p-’o’;
p++;
while(*p!=0)
/**********found**********/
n=n*8+*p-’o’;
p++;
return n;
main( )
char s[6]; int i; int n;
printf("Enter a string(Ocatal digits):");
gets(s);
if(strlen(s)>5)
printf("Error: String too longer!/n/n");
exit(0);
for(i=0; s[i]; i++)
if(s[i]<’0’||s[i]>’7’)
printf("Error: %c not is ocatal digits!/n/n", s[i]);
exit(0);
printf("The original string:");
puts(s);
n=fun(s);
printf("/n%s iS convered to integer number: %d/n/n", s, n);
[填空题]
给定程序中,函数fun的功能是:将形参std所指结构体数组中年龄最大者的数据作为函数值返回,并在main函数中输出。
请在程序的下画线处填入正确的内容,并把下画线删除,使程序得出正确的结果。
[注意] 部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在fun函数的横线上填入所编写的若干表达式或语句。
[试题源程序]
#include<stdio.h>
typedef struct
char name[10];
int age;
)STD;
STD fun(STD std[], int n)
STD max; int i;
/**********found**********/
max= (1) ;
for(i=1; i<n; i++)
/**********found**********/
if(max.age< (2) )
max=std[i];
return max;
main( )
STD std[5]="aaa", 17, "bbb", 16, "ccc", 18, "ddd", 17, "eee", 15;
STD max;
max=fun(std, 5);
printf("/nThe result: /n");
/**********found**********/
printf("/nName: %s, Age: %d/n", (3) , max.age);
[填空题]下列给定程序中,函数fun( )的功能是:根据以下公式求n的值,并作为函数值返回。例如,给指定精度的变量eps输入 0.0005时,应当输出Pi=3.140578。
n/2=1+1/3+1/3*2/5+1/3*2/5*3/7+1/3*2/5*3/7*4/9……
请改正程序中的错误,使它能得出正确的结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。
试题程序:
#include <conio.h>
#include <stdio.h>
#include <math.h>
double fun(double eps)
{double s,t; int n=t;
s=0.0;
/*************found**************/
t=1;
/*************found**************/
while(t>eps)
{ s+=t;
t=t*n/(2*n+1);
n++;
}
/*************found**************/
return (s);
}
main( )
{ double x;
printf("/nPlease enter a precision: ");
scanf("%1f",&x);
printf("/nPi=%1f/n ",fun(x));
}
[填空题]下列给定程序中函数fun( )的功能是:从低位开始取出长整型变量s中偶数位上的数,依次构成一个新数放在t中。例如,当s中的数为7654321时,t中的数为642。
请改正程序中的错误,使它能得出正确的结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。
试题程序:
#include<stdio.h>
#include <conio.h>
/*************found**************/
void fun(long s,long t)
{ long s1=10;
s/=10;
*t=s%10;
/*************found**************/
while(s<0)
{ s=s/100;
*t=s%10*s1+*t;
s1=s1*10;
}
}
main( )
{ long s, t;
clrscr( );
printf("/nPlease enter s: "); scanf
("%ld",&s);
fun(s,&t);
printf("The result is: %ld/n ",t);
}
[填空题]下列给定程序中,函数fun( )的功能是::求k!(k<13),所有阶乘的值作为函数值返回。例如:若k=10,则应输出3628800。
请改正程序中的错误,使它能得出正确的结果。
注意:不要改动main函数,不得增行或删行,也不得更
改程序的结构。
试题程序:
#include <conio.h>
#include <stdio.h>
long fun(int k)
/*************found**************/
if k>0
return (k* fun (k-l));
/*************found**************/
else if (k=0)
return 1;
main ( )
int k=10;
clrscr ( );
print, ("%d!=%1d/n ", k, fun (k));
[填空题]下列给定程序中,函数fun的功能是:计算函数F(x,y,z)=(x+y)/(x-y)+(z+y)/(z-y)的值。其中x和y的值不等,z和y的值不相等。例如,当x的值为1,y的值为2,z的值为3,函数值为2.00。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。
试题程序:
#include<stdio.h>
#include<stdio.h>
/********found********/
#define F(m,n)(m/n)
float fun(float a,float b,float c)
float s;
s=F((a+b),(a-b))+F((c+b),(c-b));
/********found********/
Return(s);
main( )
float x,y,z,sum;
printf("input x y z:");
scanf("%f%f%f",&x,&y,&z);
printf("x=%f,y=%f,z=%f/n",x,y,z);
if(x==y||y==z)
printf("Data error!/n");
exit(0);
sum=fun(x,y,z)
printf("the result is:%5.2f/n",sum);
[填空题]下列给定程序中,函数fun( )的功能是;计算函数 F(x, y ,z)=(x+ y)/(x-y)+(z+ y)/(z-y)的值。其中x和y不相等,z和y不等。例如,当x的值为9,y的值为11,2的值为15时,函数值为-3.50。
请改正程序中的错误,使它能得出正确的结果。
注意:不要改动main 函数,不得增行或删行,也不得更改程序的结构。
试题程序:
#include <stdio. h>
#include <math. h>
/**************found******************/
#define FU(m, n) (m/n)
float fun(float a, float b, float c)
{ float value;
value=FU(a+ b, a-b)+FU(c+ b, c-b);
/*************found******************/
return(Value);
}
main( )
{ float x, y, z, sum;
printf ("Input x y z:: ");
scanf("%f%f%f", &x, &y, &z);
printf("x=%f, y=%f, z=%f/n ",x, y, z);
if (x==y||y==z) {printf ("Data error! /n ");
exit (0); }
sum=fun (x, y, z);
printf("The result is:%5. 2f/n ",sum);
}
[简答题]给定程序中函数fun的功能是:从低位开始取出长整型变量S中偶数位上的数,依次构成一个新数放在t中。高位仍在高位,低位仍在低位。
例如,当s中的数为7654321时,t中的数为642。
请改正程序中的错误,使它能得到正确结果。
[注意] 不要改动main函数,不得增行或删行,也不得更改程序的结构。
[试题源程序]
#include<stdio.h>
/************found***********/
void fun(long s, long t)
long s1=10;
s/=10;
*t=s% 10;
/************found************/
while(s<0)
s=s/100;
*t=s% 10*s1+*t;
s1=s1 *10;
msin( )
long s, t;
printf("/nPlease enter s:");
scanf("%ld", &s);
fun(s, &t);
printf("The result is: %ld/n", t);
[简答题]
给定程序中函数fun的功能是:从低位开始取出长整型变量s中偶数位上的数,依次构成一个新数放在t中。高位仍在高位,低位仍在低位。
例如,当s中的数为:7654321时,t中的数为:642。
请改正程序中的错误,使它能得到正确结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。
[试题源程序]
#include<stdio.h>
/************found************/
void fun(long s,long t)
long s1=10;
s/=10;
*t=s%10;
/************found************/
while(s<0)
s=s/100;
*t=s%10*s1+ *t;
s1=s1*10;
mein( )
long s,t;
printf("/nPlease enter s:");
scanf("%1d",&s);
fun(s,&t);
printf("The result is:%1d/n",t);
[简答题]下列给定程序中,函数fun的功能是:计算N×N矩阵的主对角线元素和反向对角线元素之和,并作为函数值返回。要求先累加主对角线元素中的值,再累加反向对角线元素中的值。
例如,若N=3,有下列矩阵:
1 2 3
……
4 5 6
……
7 8 9
首先累加1、5、9,然后累加3、5、7,函数返回值为30。
请在下划线处填入正确的内容并将下划线删除,使程序得出正确的结果。
注意:部分源程序给出如下。
不得增行或删行,也不得更改程序的结构!
试题程序:
#include<stdio.h>
#define N 4
fun(int c[][N],int n)
int i,sum;
/********found********/
(1) ;
for(i=0;i<n;i++)
/********found********/
sum+= (2) ;
for(i=0;i<n;i++)
/********found********/
sum+=t[i][n-i- (3) ];
return sum;
main( )
int t[][N]=21,2,13,24,25,16,47,38,29,11,32,54,42,21,3,10,i.j;
printf("/nThe original data:/n");
for(i=0;i<N;i++)
(for[j=0;j<N;j++)
printf("%4d",t[i][j]);
printf("/n");]
printf("The result is:%d",fun(t,N));
[简答题]给定程序MODI1.C中函数fun的功能是: 比较两个字符串,将长的那个字符串的首地址作为函数值返回。
请改正函数fun中指定部位的错误, 使它能得出正确的结果。
注意: 不要改动main函数, 不得增行或删行, 也不得更改程序的结构!
给定源程序:
#include
char fun(char *s, char *t)
{ int sl=0,tl=0; char *ss, *tt;
ss=s; tt=t;
while(*ss)
{ sl++;
(*ss)++;
}
while(*tt)
{ tl++;
(*tt)++;
}
if(tl>sl) return t;
else return s;
}
main( )
{ char a[80],b[80],*p,*q; int i;
printf("/nEnter a string : "); gets(a);
printf("/nEnter a string again : "); gets(b);
printf("/nThe longer is :/n/n/"%s/"/n",fun(a,b));
}