问答题请编写函数fun,其功能是:找出2M整型二维数组中最大元素的值,并将此值返回调用函数。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。
试题程序:
#define M 4
#include <stdio.h>
int fun(int a[][M])
{
}
void main()
{
int arr[2][M]={5, 8, 3, 45, 76, -4, 12, 82};
printf(”max=% d\n, fun(arr));
}
问答题请编写函数fun,其功能是:将一组得分中,去掉一个最高分和一个最低分,然后求平均值,并通过函数返回。函数形参a指向存放得分的数组,形参n中存放得分个数(n>2)。 例如,若输入9.9 8.5 7.6 8.5 9.3 9.58.9 7.8 8.6 8.4十个得分,则输出结果为8.687500。 注意:请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。 试题程序:#include<stdio.h>void NONO();double fun(double a[],int n){}main(){double b[10],r;int i;prinff(“输入10个数放入b数组中:”);for(i=0;i<10;i++) scanf(“%If”,&b[i]); prinff(“输入的10个数是:”); for(i=0;i<10;i++) prinff(“%4.1lf”,b[i]); prinff(“\n”); r=fun(b,10); prinff(“去掉最高分和最低分后的平均分:%f\n”,r); NONO();}void NONO()/*本函数用于打开文件,输入数据,调用函数,输出数据,关闭文件。*/{FILE*fp.*wf;int i,j;double b[10],r;fp=fopen(“in.dat”,“r”);wf=fopen(“out.dat”,“w”);for(i=0;i<10;i++){ for(j=0;j<10;j++) { fscanf(fp,“%If”,&b[j]); } r=fun(b,10); fprintf(wf,“%f\n”,r); } fclose(fp); fclose(wf);}
问答题编写函数fun,其功能是:根据以下公式求P的值,结果由函数值带回。m与n为两个正整数且要求m>n。例如:m=12,13=8时,运行结果为495.000000。注意:部分源程序在文件PROG1.C中。请勿改动主函数main和其他函数中的任何内容。仅在函数fun的花括号中填入你编写的若干语句。试题程序:#include<stdio.h>floatfun(intm,intn){}main()/*主函数*/{voidNONO();prLntf("P=%f/n",fun(12,8));NONO();}voidNONO(){/*本函数用于打开文件,输入数据,调用函数,输出数据,关闭文件。*/FILE,*fp,*wf;inti,m,n;floats;fp=fopen("in.dat","r");wf=fopen("out.dat","w");for(i=0;i<10;i++){fscanf(fp,"%d,%d",&m,&n);s=fun(m,n);fprintf(wf,"%f/n",s);}fclose(fp);fclose(wf);}
问答题函数fun的功能是:将a、b中的两个两位正整数合并形成一个新的整数放在c中。合并的方式是:将a中的十位和个位数依次放在变量c的百位和个位上,b中的十位和个位数依次放在变量c的千位和十位上。
例如,当a=45,b=12,调用该函数后,c=1425。
注意:部分源程序存在文件PROG1.C中。数据文件IN.DAT中的数据不得修改。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。
给定源程序:
#include <stdio.h>
void fun(int a,int b,long *c.
{
}
main()/*主函数*/
{int a,b;long c;
printf("Input a b:");
scanf("%d%d",
fun(a,b,
printf("The result is:%ld/n",c);
}
问答题函数fun的功能是:将s所指字符串中除下标为偶数,同时ASCⅡ码值也为偶数的字符外,其余的全部删除;字符串中剩余字符所形成的新串放在t所指的数组中。 例如,若s所指字符串中的内容为“ABCDEFGl23456”,其中字符A的ASCⅡ码值为奇数,因此应当删除;字符B的ASCⅡ码值为偶数,但在数组中的下标为奇数,因此也应当删除;字符2的ASCⅡ码值为偶数,在数组中的下标也为偶数,因此不应当删除,其他以此类推。最后t所指的数组中的内容应是“246”。 注意:请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。 试题程序:#include<stdio.h>#include<string.h>void fun(char*s,char t[]){}main(){ char s[100],t[100]; void NONO(); prinff(“\nPlease enter string s:”); scanf(“%s”,S); fun(s,t); prinff(“\nThe result is:%s\n”,t); NONO();}void NONO()/*本函数用于打开文件,输入数据,调用函数,输出数据,关闭文件。*/{ char S[100],t[100]; FILE,*rf,*wf; int i; rf=fopen(“in.dat”,“r”);wf=fopen(“out.dat”,“w”);for(i=0;i<10;i++){ fscanf(ff,“%s”,s); fun(s,t); fprinff(wf,“%s\n”,t);}fclose(rf);fclose(wf(;
问答题请编写一个函数int fun(int*s,int t,int *k),用来求出数组的最大元素在数组中的下标并存放在k所指向的存储单元中。
例如,输入如下整数:
876 675 896 101 301 401 980 431 451 777
则输出结果为6,980。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。
试题程序:
#include<stdlib.h>
#include<conio.h>
#include<stdio.h>
int fun(int *s,int t,int *k)
{
}
void main()
{
int a[10]=(876,675,896,101,301,401,980,431,451,777},k;
system("CLS");
fun(a,10,&k);
printf("%d,%d/n",k,a[k]);
}
问答题规定输入的字符串中只包含字母和*号。请编写函数fun,其功能是:除了字符串前导的*号之外,将串中其他*号全部删除。在编写函数时,不得使用C语言提供的字符串函数。例如,字符串中的内容为:“****A*BC*DEF*G*******”,删除后,字符串中的内容应当是:“****ABCDEFG”。注意:部分源程序在文件PROG1.C中。请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。#include<stdio.h>voidfun(char*a){}main(){char s[81];void NONO();printf("Ente ra string:\n");gets(s);fun(s);printf("The string after deleted:\n");puts(S);NONO();}void NONO(){/*本函数用于打开文件,输入数据,调用函数,输出数据,关闭文件。*/FILE*in,*out;int i;char s[81];in=fopen("in.dat","r");out=fopen("out.dat","w");for(i=0;i<10;i++){fscanf(in,"%s",s);fun(s);fprintf(out,"%s\n",s);}fclose(in);fclose(out);}
问答题给定程序中已建立一个带有头结点的单向链表,在main函数中将多次调用fun函数,每调用一次fun函数,输出链表尾部结点中的数据,并释放该结点,使链表缩短。
请在程序的下划线处填入正确的内容并把下划线删除,使程序得出正确的结果。
注意:源程序存放在考生文件夹下的BLANK1.C中。
不得增行或删行,也不得更改程序的结构!
#include
#include
#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)
t=t—> 1 ;
}
printf(" %d ",____2____) ;
s—>next=NULL;
}
SLIST *creatlist (int *a)
{SLIST *h,*p,*q; int i;
h=p= (SLIST *) malloc (sizeof (SLIST));
{ cF (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 (p==NULL) printf("/nThe list
is NULL ! /n") ;
else
{ printf ("/nHead") ;
do { printf ("—>%d",p—>data) ;
p=p—>next; } while (p ! =NULL) ;
printf ( "—>End/n") ;
}
main ()
{SLIST *head;
int a[N] ={11,12,15,18,19,22,25, 29};
head=creatlist (a) ;
printf ("/nOutput from head:/n") ;
outlist (head) ;
printf ( "/nOutput from tail: /n") ;
while (head—>next != NULL) {
fun (head) ;
printf ("/n/n");
printf("/nOutput from head
again :/n") ; outlist (head) ;
}
}
问答题函数fun的功能是进行数字字符转换。若形参ch中是数字字符'0'~'9',则'0'转换成'9','1'转换成'8','2'转换成'7',……,'9'转换成'0';若是其他字符则保持不变;并将转换后的结果作为函数值返回。
请在程序的下划线处填入正确的内容并把下划线删除,使程序得出正确的结果。
注意:源程序存放在考生文件夹下的BLANK1.C中。
不得增行或删行,也不得更改程序的结构!
#include
/********** found**********/
【1】 fun(char ch)
{
/**********found**********/
if (ch>='0'
return ch ;
}
main ()
{ char cl, c2;
printf("/nThe result :/n");
cl='2'; c2 = fun(cl);
printf ("cl=%c c2=%c/n", cl,
c2);
cl='8'; c2 = fun(cl);
printf("cl=%c c2=%c/n", cl, c2) ;
cl='a'; c2 = fun(cl);
printf("cl=%c c2=%c/n", cl, c2);
}
问答题请编写程序统计输入的行数,用!号结束输入,!号所在行不计入行数。
问答题给定程序中,函数fun的功能是将不带头结点的单向链表逆置,即若原链表中从头至尾结点数据域依次为2、4、6、8、10,逆置后,从头至尾结点数据域依次为10、8、6、4、2。
请在程序的下画线处填入正确的内容并把下画线删除,使程序得出正确的结果。
注意:部分源程序给出如下。
不得增行或删行,也不得更改程序的结构!
试题程序:
#include<stdio.h>
#include<stdlib.h>
#define N 5
typedef struer node{
int data;
struct node*next;
}NODE;
/*********found*********/
【1】
*fun(NODE*h)
{ NODE*P,*q,*r;
p=h ;
if(P==NULL)
return NULL;
q=P->next;
P->next=NULL;
while(q)
{
/*********found*********/
r=q->
【2】
;
q->next=p;
p=q;
/*********found*********/
q=
【3】
;
}
return P;
}
NODE*creatlist (int a[])
{ NODE*h,*P,*q;int i;
h=NULL;
for(i=0;i<N;i++)
{ q=(NODE*)malloc(sizeof (NODE));
q->data=a[i];
q->next=NULL;
if (h==NULL)h=p=q;
else{P->next=q;p=q;)
}
return h;
}
void outlist(NODE*h)
{ NODE*p;
p=h;
if(P==NULL)
printf("The list is NULL!\n");
else
{printf("\nHead");
do
{printf("->%d",P->data);
p=p->next;)
while(P!=NULL);
printf("->End\n”);
}
}
main()
{ NODE*head;
int a[N]={2,4,6,8,10};
head=creatlist(a);
printf("\nThe original list:\n");
outlist(head);
head=fun(head);
printf("\nThe list after inverting:\n");
outlist(head);
}
问答题下列给定程序中,函数fun的功能是:将p所指字符串中的所有字符复制到b中,要求每复制3个字符之后插入一个空格。 请改正程序中的错误,使它能得出正确结果。 注意:不要改动main函数,不得增行或删行,也不得更改程序的结构! 试题程序: #include <stdio.h > void fun (char * p, char * b) int i, k=0; while (* p) i=1; while (i<=3 && * p) /**********found********** / b[k]=p; k++; p++; i++; if(* p) /**********found********** / b[k++]" "; b[k]='/0'; main () char a[80], b[80]; printf ("Enter a string:"); gets (a); printf ("The original string: "); puts (a); fun (a, b); printf ("/nThe string after insert space: "); puts (b); printf ("/n/n");
问答题请编写函数fun, 函数的功能是: 将M行N列的二维数组中的字符数据, 按列的顺序依次放到一个字符串中。
例如, 二维数组中的数据为:
W W W W
S S S S
H H H H
则字符串中的内容应是: WSHWSHWSH。
注意:部分源程序在文件PROG1.C中。
请勿改动主函数main和其它函数中的任何内容, 仅在函数fun的花括号中填入你编写的若干语句。
给定源程序:
#include
#define M 3
#define N 4
void fun(char s[][N], char *b)
{
int i,j,n=0;
for(i=0; i < N;i++) /* 请填写相应语句完成其功能 */
{
}
b[n]='/0';
}
main()
{ char a[100],w[M][N]={{'W','W','W','W'},{'S','S','S','S'},{'H','H','H','H'}};
int i,j;
printf("The matrix:/n");
for(i=0; i
{ for(j=0;j3c",w[i][j]);
printf("/n");
}
fun(w,a);
printf("The A string:/n");puts(a);
printf("/n/n");
NONO();
}
问答题下列程序定义了M×M的二维数组,并在主函数中赋值。请编写函数proc(),函数的功能是:求出数组周边元素的平均值并作为函数值返回给主函数中的s。例如,若a数组中的值为: a=0 1 2 3 4 5 9 7 4 5 4 3 8 3 6 3 5 6 8 7 2 1 0 9 8 则返回主程序后,S的值为3.750000。 注意:部分源程序已给出。 请勿改动主函数main和其他函数中的任何内容。 试题程序: #include<stdio.h> #include<conio.h> #include<stdlib.h> #define M 5 double proc(int w[][M]) void main() int a[M][M]=0, 1, 2, 3, 4, 5, 9, 7, 4, 5, 4, 3, 8, 3, 6, 3, 5, 6, 8, 7, 2, 1, 0, 9, 8; int i, j; double s; system("CLS"); printf("*****The array*****/n"); for(i=0; i<M; i++) for(j=0; j<M; j++) printf("%4d", a[i][j]); printf("/n"); s=proc(a); printf("*****THE RESULT*****/n"); printf("The sum is: %lf/n", s);
问答题请编写函数fun(),它的功能是:判断字符串是否是回文?若是,函数返回1,主函数中输出:YES,否则返回0,主函数输出NO。回文是指顺读和倒读都一样的字符串。 例如,字符串LEVEL是回文,而字符串12312就不是回文。 [注意] 部分源程序给出如下。 请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。 [试题源程序] #include<stdio.h> #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(); NONO() /*请在此函数内打开文件,输入测试数据,调用fun函数,输出数据,关闭文件。*/ FILE *rf, *wf; int i ; char s[N]; rf=fopen("K://k06//24010001//in.dat", "r"); wf=fopen("K://k06//24010001//out.dat", "w"); for(i=0; i<10; i++) fscanf(rf, "%s", s); if(fun(S)) fprintf(wf, "%s YES/n", s); else fprintf(wf, "%s NO/n", s); fclose(rf); fclose(wf);
问答题下列给定程序中,函数fun()的功能是:将p所指字符串中的所有字符复制到b中,要求在每复制3个字符之后插入1个空格。
例如,若给a输入字符串:“ABCDEFGHIJK”,调用函数后,字符数组b中的内容为:“ABC DEF GHI JK”。
请改正程序中的错误,使它能得出正确结果。
注意:不要改动main()函数,不得增行或删行,也不得更改程序的结构。
试题程序:
#include<stdio.h>
void fun(char*p, char*b)
{ int i, k=0;
while(*p)
{ i=1;
while(i<=3
k++; p++; i++;
}
if(*p)
{
//****found****
b[k++]=" ";
}
}
b[k]="/0";
}
void main()
{char a[80], b[80];
printf("Enter a string:");
gets(a);
printf("The original string:");
puts(a);
fun(a, b);
printf("/nThe string after insert space:");
puts(b); printf("/n/n");
}
问答题下列给定程序中,函数fun的功能是:求S的值。
S=(2
2
/(1×3))×(4
2
/(3×5))×(6
2
/(5×7))×…×(2k)
2
/((2k-1)×(2k+1))
例如,当k为10时,函数的值应为1.533852。
请改正程序中的错误,使它能得出正确的结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构!
试题程序:
#include<stdlib.h>
#include<conio.h>
#include<stdio.h>
#include<math.h>
/********found********/
double fun(int k)
{
int n;float s,w,p,q;
n=1;
s=10;
while(n<=k)
{
w=2.0*n;
P=w-1.0;
q=w+1.0;
s=s*w*w/p/q;
n++;
}
/********found********/
return s
}
void main()
{system("CLS");
printf("%f/n",fun(10));
}
问答题
给定程序MODI1.C中函数fun的功能是:将m(1≤m≤10)个字符串连接起来,组成一个新串,放入pt所指存储区中。
例如:把3个串:"abc","CD","EF"连接起来,结果是“abcCDEF”。
请改正程序中的错误,使它能得出正确的结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构!
#include<stdio.h>
#include<string.h>
void fun(char str[][10], int m, char *pt)
{
/**********found**********/
Int k, q, i;
for (k=0; k<m; k++)
{ q=strlen(str[k]);
for(i=0; i<q; i++)
/**********found**********/
pt[i]=str[k, i];
pt+=q;
pt[0]=0;
}
}
main()
{int m, h;
char s[10][10], p[120];
printf("/nPlease enter m:");
scanf("%d", gets(s[0]);
printf("/nPlease enter %d string:/n", m);
for(h=0; h<m; h++)gets(s[h]);
fun(s, m, p);
printf("/nThe result is:%s/n", p);
}
问答题给定程序MODI1.C中fun函数的功能是:求
s=aa…aa-…-aaa-aa-a
(此处aa…aa表示n个a,a和n的值在1至9之间)
例如a=3,n=6,则以上表达式为:
s=333333-33333-3333-333-33-3
其值是:296298
a和n是fun函数的形参,表达式的值作为函数值传回main函数。
请改正程序中的错误,使它能计算出正确的结果。注意:不要改动main函数,不得增行或删行,也不得更改程序的结构!
#include
long fun (int a, int n)
{ int j ;
/************ found************/
long s = 0, t= 1 ;
for (j = 0 ; j < n ; j++)
t = t * 10 + a ;
s = t ;
for (j = 1 ; j < n ; j++) {
/************ found************/
t = t % 10 ;
s = s - t ;
}
return(s);
}
main()
{ int a, n ;
printf("/nPlease enter a and n:");
scanf("%d%d",
printf("The value of function
is: %ld/n", fun (a, n) ) ;
}
问答题编写一个函数,输入n个字符串,串与串之间以Enter键分隔,找出最短字符串中第一个字符串,传回该串地址(用一个新串“*”作为结束输入的标志)。
注意:部分源程序给出如下。
请勿改动main()函数和其他函数中的任何内容,仅在函数fun()的花括号中填入所编写的若干语句。
试题程序:
#include<stdio.h>
#include<string.h>
#include<conio.h>
char*fun(char(*s)[100],int num)
{
}
void main()
{
char str[10][100],*min;
int n,i=0;
FILE*out;printf("input strings with"*"
as end:");
gets(str[i]);
puts(str[i]);
while(!strcmp(str[i],"*")==0)
{
i++;
gets(str[i]);
puts(str[i]);
}
n=1;
min=fun(str,n);
printf("/nmin=%s/n",min);
out=fopen("outfile.dat","w");
strcpy(str[0],"just,");
strcpy(str[1],"a");
strcpy(str[2],"test");
strcpy(str[3],"some");
strcpy(str[4],"tool?!?");
fprintf(out,"%s",fun(str,5));
fclose(out);
}