问答题给定程序中, 函数fun的功能是用函数指针指向要调用的函数,并进行调用。
规定在__2__处使f指向函数f1,在__3__处使f指向函数f2。当调用正确时,程序输出:
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; }
double fun(double a, double b)
{
/**********found**********/
__1__ (*f)();
double r1, r2;
/**********found**********/
f = __2__ ; /* point fountion f1 */
r1 = f(a);
/**********found**********/
f = __3__ ; /* point fountion f2 */
r2 = (*f)(a, b);
return r1 + r2;
}
main()
{ double x1=5, x2=3, r;
r = fun(x1, x2);
printf("/nx1=%f, x2=%f, x1*x1+x1*x2=%f/n",x1, x2, r);
}
问答题下列给定程序中,函数proc()的功能是:给一维数组arr输入任意4个整数,并按如下的规律输出。例如,若输入2 3 4 5,则程序运行后输m以下矩阵:
5 2 3 4
4 5 2 3
3 4 5 2
2 3 4 5
请修改程序中的错误,使它能得出正确的结果。
注意:不要改动main()函数,不得增行或删行,也不得更改程序的结构。
试题程序:
#include<stdio.h>
#define N 4
//****found****
void proc(int arr)
{
int i, j, k, m;
print(("Enter 4 number:");
for(i=0; i<N; i++) scanf("%d",
printf("/n/nThe result:/n/n");
for(i=N; i>0; i--)
{
k=arr[N-1];
for(j=N-1; j>0; j--)
//****found****
arr[j]=arr[j+1];
arr[0]=k;
for(m=0; m<N; m++)printf("%d", arr[m]);
printf("/n");
}
}
void main()
{
int a[N];
proc(a); printf("/n/n");
}
问答题编写一个函数,其功能是:从传入的num个字符中找出最长的一个字符串,并通过形参指针max传回该串地址(用****作为结束输入的标识)。 注意:部分源程序在文件PROG1.C中。 请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。 试题程序:#include < conio.h >#include < stdio.h >#include < string.h >#include < stdlib.h >char* fun (char (* a)[81], intnum, char *max){}void main(){ FILE *wf; char ss[10][81], *ps =NULL; char s[3] [81] ={"abcd","deg", "diegns"),*p= NULL; int i=0,n; system( "CLS"); printf("输入若干个字符串:"); gets (ss[i]); puts (ss[i]); while(!strcmp (ss[i],"****")==0)/*用4个星号作为结束输入的标志*/ { i++; gets (ss[i]); puts (ss[i]); } n=it ps = fun (ss,n,ps) ; printf "/nmax = % s/n",ps) ;/******************/ wf = fopen ("out.dat", "w") ; p = fun (s,3, p) ; fprintf (wf, "% s",p) ; fclose (wf) ;/******************/ }
问答题下列给定程序中,函数proc()的功能是求出数组中最小数和次最小数,并把最小数和arr[0]中的数对调,次最小数和arr[1]中的数对调。
请修改程序中的错误,使它能得到正确结果。
注意:不要改动main()函数,不得增行或删行,也不得更改程序的结构。
试题程序:
#include<stdio.h>
#include<conio.h>
#include<stdio.h>
#define M 20
void proc(int *arr, int n)
{
int i, m, t, k;
//****found****
for(i=0; i<n; i++)
{
m=i;
for(k=i; k<n; k++)
if(arr[k]<arr[m])
//****found****
k=m;
t=arr[i];
arr[i]=arr[m];
arr[m]=t;
}
}
void main()
{
int b[M]={11, 5, 12, 0, 3, 6, 9, 7, 10, 8},
n=10, i;
system("CLS");
for(i=0; i<n; i++)
printf("%d", b[i]);
printf("/n");
proc(b, n);
for(i=0; i<n; i++)
printf("%d", b[i]);
printf("/n");
}
问答题下列给定程序中,函数fun()的功能是求出数组中最小数和次最小数,并把最小数和a[0]中的数对调,次最小数和a[1]中的数对调。 请改正程序中的错误,使它能得到正确结果。 注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。 [试题源程序] #include<stdio.h> #include<conio.h> #define N 20 void fun(int * a,intn) int i,m,t,k; /**********************found***********************/ for(i=0;i<n;i++) m=i; for(k=i;k<n;k++) if(a[k]<a[m]) /**********************found***********************/ k=m; t=a[i]; a[i]=a[m]; a[m]=t;
问答题请编写函数fun, 函数的功能是: 判断字符串是否为回文?若是, 函数返回1,主函数中输出: YES, 否则返回0, 主函数中输出NO。回文是指顺读和倒读都一样的字符串。
例如, 字符串LEVEL是回文, 而字符串123312就不是回文。
注意:部分源程序在文件PROG1.C中。请勿改动主函数main和其它函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。
给定源程序:
#include
#define N 80
int fun(char *str)
{
}
main()
{ char s[N] ;
printf("Enter a string: ") ; gets(s) ;
printf("/n/n") ; puts(s) ;
if(fun(s)) printf(" YES/n") ;
else printf(" NO/n") ;
NONO() ;
}
问答题编写函数fun(),其功能是:根据以下公式求的值(要求精度0.0005,即某项小于0.0005时停止迭代)。程序运行后,若输入精度0.0005,则程序应输出为3.14…。注意:部分源程序给出如下。请勿改动main()函数和其他函数中的任何内容,仅在函数fun()的花括号中填入所编写的若干语句。试题程序:#include<stdio.h>#include<conio.h>#include<math.h>doublefun(doubleeps){}voidmain(){doublex;printf("Inputeps:");scanf("%1f",printf("/neps=%1f,PI=%1f/n",x,fun(x));}
问答题请编写函数fun,该函数的功能是:判断字符串是否为回文,若是,则函数返回1,主函数中输出“YES”,否则返回0,主函数中输出“NO”。回文是指顺读和倒读都一样的字符串。 例如,字符串LEVEL是回文,而字符串123312就不是回文。 注意:请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。试题程序:#include<stdio.h>#define N 80int fun(char*str){}main(){ char s[N]; FILE*out; char*test[]={“1234321”,“123421”“123321”,“abcdCBA”}; int i; prinff(“Enter a string:”); gets(S); prinff(“\n”); puts(s); if(fun(s)) prinff(“YES\n”); else printf(“NO\n”);/****************/ out=fopen(“out.dat”,“w”); for(i=0;i<4;i++) if(fun(test[i])) fprintf(out,“YES\n”); else fprinff(out,“NO\n”); felose(out);/****************/}
问答题请编写一个函数fun,它的功能是:将SS所指字符串中所有下标为奇数位置的字母转换为大写(若该位置上不是字母,则不转换)。
例如,若输入"abc4Efg",则应输出"aBc4EFg"。
注意:部分源程序在文件PROG1.C中。请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。
试题程序:
#include
#include
#include
#include
void fun(char*ss)
{
}
void main()
{
FILE*wf;
char tt[81],s[81]="abe4Efg";
system("CLS");
printf("\nPlease enter an string within 80 characters:\n");
gets(tt);
printf("\n\nAfter changing,the string\n%8",tt);
fun(tt);
printf("\nbecomes\n%s\n",tt);
/******************************/
wf=fopen("out.dat","w");
fun(s);
printf(wf,"%s",s);
fclose(wf);
/*****************************/
}
问答题下列给定程序中,函数proc()的功能是:传入一个整数n,计算如下公式的值。
t=1/2-1/3-…-1/n
例如,若输入3,则应输出0.166667。
请修改程序中的错误,使它能得出正确的结果。
注意:不要改动main()函数,不得增行或删行,也不得更改程序的结构。
试题程序:
#include<stdlib.h>
#include<conio.h>
#include<stdio.h>
double proc(int n)
{
double t=1.0;
int i;
for(i=2; i<=n; i++)
//****found****
t=1.0-1/i;
//****found****
}
void main()
{ int m;
system("CLS");
printf("/nPlease enter 1 integer numbers: /n");
scanf("%d",
printf("/n/nThe result is %1f/n", proc(m));
}
问答题编程将文件read.txt中的字符读出显示到屏幕上。
问答题给定程序中函数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);
问答题给定程序modil.c的主函数中,将a、b、c三个节点链成一个单向链表,并给各节点的数据域赋值,函数fun()的作用是:累加链表节点数据域中的数据作为函数值返回。请改正函数fun中指定部位的错误,使它能得出正确的结果。注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。试题程序:#include〈stdio.h〉typedef struct list{int data;struct list*next;}LIST;int fun(LIST*h){LIST*P;/**********found**********/int t:p=h;/**********found**********/while(*p){/**********found**********/t=t+p.data;p=(*p).next;}return t:}main(){LIST a,b,c,*h;a.data=34;b.data=51;c.data=87;e.next='\0';h=&a;a.next=&b;b.next=&c;printf(''总和=%d\n'',fun(h));}
问答题请编写函数void fun(int x, int pp[], int *n),它的功能是:求出能整除x且不是偶数的各整数,并按从小到大的顺序放在即所指的数组中,这些除数的个数通过形参n返回。 例如,若x中的值为30,则有4个数符合要求,它们是1, 3,5,15。 注意:部分源程序给出如下。 请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。 试题程序: #include <conio.h> #include <stdio.h> void fun (int x, int pp[], int *n) main() int x,aa[1000], n, i ; clrscr(); printf("/nPlease enter an integer number : /n ") ; scanf ("%d", fun (x, aa, for (i=0 ; i<n ; i++) printf ("%d ", aa [i]); printf ("/n ") ;
问答题请编写函数fun,其功能是:计算并输出3~n之间(含3和n)所有素数的平方根之和。 例如,在主函数中从键盘为n输入100后,输出为:sum=148.874270。 [注意] 要求n的值大于2但不大于100。 [注意] 部分源程序给出如下。请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。 [试题源程序] #include<math.h> #include<stdio.h> double fun(int n) main() int n; double sum; printf("/n/nInput n:"); scanf("%d", &n); sum=fun(n); printf("kn/nsum=%f/n/n", sum);
问答题给定程序中,函数fun的功能是:利用指针数组对形参ss所指字符串数组中的字符串按由长到短的顺序排序,并输出排序结果。ss所指字符串数组中共有N个字符串,且串长小于M。 请在程序的下画线处填入正确的内容并把下画线删除,使程序得出正确的结果。注意:不得增行或删行,也不得更改程序的结构! 试题程序:#inelude<stdio.h>#include<string.h>#deftne N 5#deftne M 8void fun(char(*ss)[M]){ char*ps[N],*tp;int i,j,k; for(i=0;i<N;i++) ps[i]=ss[i]; for(i=0;i<N一1;i++) {/******found******/ k=___1___; for(j=i+1;j<N;j++)/******found******/ if(strlen(ps[k])<strlen(__2__)) k=j; [i] tp=ps[j]; ps[i]=ps[k];/******found******/ ps[k]=___3___; } prinff(“\nThe string after sorting by length:\n\n”)for(i=0;i<N;i++)puts(ps[i]);}main(){char eh[N][M]={“red”,“green”,“blue”,“yellow”,“black”}; int i; printf(“\nThe origin-1 string\n\n”); for(i=0;i<N;i++)puts(ch[i]); printf(“\n”); fun(oh);}
问答题请编写一个函数,函数的功能是删除字符串中的所有空格。
例如, 主函数中输入"asd af aa z67", 则输出为 "asdafaaz67"。
注意:部分源程序在文件PROG1.C中。
请勿改动主函数main和其它函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。
给定源程序:
#include
#include
int fun(char *str)
{
}
main()
{
char str[81];
int n;
printf("Input a string:") ;
gets(str);
puts(str);
fun(str);
printf("*** str: %s/n",str);
NONO();
}
问答题给定程序中,函数fun的功能是将带头结点的单向链表逆置。即若原链表中从头至尾结点数据域依次为:2、4、6、8、10,逆置后,从头至尾结点数据域依次为:10、8、6、4、2。 请在程序的下划线处填入正确的内容并把下划线删除,使程序得出正确的结果。 注意:源程序存放在考生文件夹下的BLANK1.C中。 不得增行或删行,也不得更改程序的结构!1 #include<stdio.h>2 #include<stdlib.h>3 #define N 54 typedef struct node{5 int data;6 struct node *next;7 } NODE;8 void fun(NODE *h)9 { NODE *p,*q,*r;10 /**********found**********/11 p=h->___1___;12 /**********found**********/13 if(p==__2__)return;14 q=p->next;15 p->next=NULL;16 while(q)17 { r=q->next;q->next=p;18 /**********found**********/19 p=q;q=__3__ ;20 }21 h->next=p;22 }23 NODE *creatlist(int a[])24 { NODE *h,*p,*q;int i;25 h=(NODE *)malloc(sizeof(NODE));26 h->next=NULL;27 for(i=0;i<N;i++)28 { q=(NODE *)malloc(sizeof(NODE));29 q->data=a[i];30 q->next=NULL;31 if(h->next==NULL)h->next=p=q;32 else{p->next=q;p=q;}33 }34 return h;35 }36 void outlist(NODE *h)37 { NODE *p;38 p=h->next;39 if(p==NULL)printf(''The 1ist is NULL!\n'');40 else41 { printf(''\nHead'');42 do43 { printf(''->%d”,p->data);p=p->next;}44 while(p!=NULL);45 printf(''->End\n'');46 }47 }48 main()49 { NODE *head;50 int a[N]={2,4,6,8,10};51 head=creatlist(a);52 printf(''\nThe original list:\n'');53 outlist(head);54 fun(head);55 printf(''\nThe list after inverting:\n¨);56 outlist(head);57 }
问答题假定输入的字符串中只包含字母和*号。请编写函数fun,它的功能是:只删除字符串前导和尾部的*号,串中字母之间的*号都不删除。形参n给出了字符串的长度, 形参h给出了字符串中前导*号的个数,形参e给出了字符串中最后*号的个数。在编写函数时,不得使用C语言提供的字符串函数。
例如,字符串中的内容为:****A*BC*DEF*G*******,删除后,字符串中的内容应当是:A*BC*DEF*G。
注意: 部分源程序在文件PROG1.C文件中。请勿改动主函数main和其它函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。
给定源程序:
#include
void fun( char *a, int n,int h,int e )
{
}
main()
{ char s[81],*t,*f; int m=0, tn=0, fn=0;
printf("Enter a string:/n");gets(s);
t=f=s;
while(*t){t++;m++;}
t--;
while(*t=='*'){t--;tn++;}
while(*f=='*'){f++;fn++;}
fun( s , m,fn,tn );
printf("The string after deleted:/n");puts(s);
NONO();
}
问答题给定程序MODI1.C中函数fun的功能是:将s所指字符串中位于奇数位置的字符或ASCII码为偶数的字符放入t所指数组中(规定第一个字符放在第0位中)。 例如,字符串中的数据为:AABBCCDDEEFF,则输出应当是:ABBCDDEFF。 请改正函数fun中指定部位的错误,使它能得出正确的结果。 注意:不要改动main函数,不得增行或删行,也不得更改程序的结构!#include <stdio.h>#include <string.h>#define N 80void fun(char *s, char t[]){ int i, j=0;for(i=0; i<(int)strlen(s);i++)/***********found***********/if(i%2 /***********found***********/t[i]='/0';}main (){ char s[N], t[N] ;printf("/nPlease enter string s : "); gets (s);fun (s, t);printf("/nThe resultis : %s/n",t); }
