问答题假定输入的字符串中只包含字母和*号。请编写函数 fun(),它的功能是:将字符串中的前导*号全部删除,中间和后面的*号不删除。 例如,若字符串中的内容为****A*BC*DEF*G*******,删除后,字符串中的内容则应当是A*BC*DEF*G*******。 注意:部分源程序给出如下。 请勿改动主函数main 和其他函数中的任何内容,仅在函数fun 的花括号中填入所编写的若干语句。 试题程序; #include <stdio. h> #include <conio. h> void fun (char *a) main() char s[81]; printf("Enter a string :/n"); gets (s); fun (s); printf ("The string after deleted: /n"); puts (s);
问答题给定程序的功能是:从键盘输入若干行文本(每行不超过80个字符),写到文件myfile4.txt中,用-1作为字符串输入结束的标志。然后将文件的内容读出显示在屏幕上。文件的读写分别由自定义函数ReadText和WriteText实现。 请在程序的下划线处填入正确的内容并把下划线删除,使程序得出正确的结果。 注意:源程序存放在考生文件夹下的BLANK1.C中。 不得增行或删行,也不得更改程序的结构!1 #include<stdio.h>2 #include<string.h>3 #include<stdlib.h>4 void WriteText(FILE *);5 void ReadText(FTLE *);6 main()7 { FILE *fp;8 if((fp=fopen(''myfile4.txt'',''w''))==NULL)9 {printf(''open fail!!\n'');exit(0);}10 WriteText(fp);11 fclose(fp);12 if((fp=fopen(''myfile4.txt'',''r''))==NULL)13 {printf(''open fail!!\n'');exit(0);}14 ReadText(fp);15 fclose(fp);16 }17 /**********found**********/18 void WriteText(FTLE __1__ )19 { char str[81];20 printf(''\nEnter string with-1 to end:\n'');21 gets(sir);22 while(strcmp(str,''-1'')!=0){23 /**********found**********/24 fputs(__2__,fw);fputs(''\n'',fw);25 gets(str);26 }27 }28 void ReadText(FILE *fr)29 { char str[81];30 printf(''\nRead file and output to screen:\n'');31 fgets(str,81,fr);32 while(!feof(fr)) {33 /**********found**********/34 printf(''%s'',__3__);35 fgets(str,81,fr);36 }37 }
问答题请编写函数fun,其功能是:移动字符串中的内容,移动的规则是把第1~m个字符,平移到字符串的最后,把第m+1到最后的字符移到字符串的前部。
例如,字符串中原有的内容为“ABCDEFGHIJK”,m的值为3,移动后,字符串中的内容应该是“DEFGHIJKABC”。
注意
:部分源程序给出如下。
请勿改动main函数和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。
试题程序:
#include<stdio.h>
#include<string.h>
#define N 80
void fun(char *w,int m)
{
}
void main()
{
char a[N]="ABCDEFGHIJK";
int m;
printf("The origina string:/n");
puts(a);
printf("/n/nEnter m:");
scanf("%d",
fun(a,m);
printf("/nThe string after moving:/n");
puts(a);
printf("/n/n");
}
问答题下列程序定义了M×M的二维数组,并在主函数中自动赋值。请编写函数proc(int arr[][M]),该函数的功能是使数组右上半三角元素中的值全部置成0。例如a数组中的值为:
arr=1 2 3
4 5 6
7 8 9,
则返回主程序后a数组中的值应为:
arr=0 0 0
4 0 0
7 8 0
注意:部分源程序给出如下。
请勿改动main()函数和其他函数中的任何内容,仅在函数proc()的花括号中填入所编写的若干语句。
试题程序:
#include<conio.h>
#include<stdio.h>
#inciude<stdlib.h>
#include<time.h>
#define M 5
void proc(int arr[][M])
{
}
void main()
{
int arr[M][M], i, j;
srand((unsigned)time(NULL));
system("CLS");
printf("****The array****/n");
for(i=0; i<M; i++)
//产生一个随机的5*5矩阵
{
for(j=0; j<M; j++)
{
arr[i][j]=rand()%10;
printf("%4d", arr[i][j]);
}
printf("n");
}
proc(arr);
printf("THE RESULT/n");
for(i=0; i<M; i++)
{
for(j=0; j<M; j++)
printf("%4d", arr[i][j]);
printf("/n");
}
}
问答题下列给定程序中,函数fun的功能是:求ss所指字符串数组中长度最短的字符串所在的行下标,作为函数值返回,并把其串长放在形参n所指的变量中。ss所指字符串数组中共有M个字符串,且串长小于N。 请在下画线处填入正确的内容并将下画线删除,使程序得出正确的结果。 注意:部分源程序给出如下。 不得增行或删行,也不得更改程序的结构! 试题程序: #include <stdio.h> #include < string.h > #define M 5 #define N 20 int fun(char (* ss)[N], int * n) int i, k=0, len=N; /********** found********** / for(i=0; i< (1) ; i++) len=strlen (ss[ i]); if(i==0) * n=fen; /********** found*********** / iffen (2) * n) * n=len; k=i; /********** found********** / return ( (3) ); main () char ss[M] [N]="shanghai", "guangzhou", "beijing", "tianjing", "chongqing" ; int n, k, i; printf (" /nThe original strings are :/n"); for (i=0; i<M; i++)puts (ss[i]); k=fun (ss, printf ("/nThe length of shortest string is : % d/n", n); printf ("/nThe shortest string is : % s/n", ss[k]);
问答题下列给定程序中,函数fun()的作用是,将字符串tt中的大写字母都改为对应的小写字母,其他字符不变。例如,若输入"Ab,cD",则输出"ab, cd"。 请改正函数fun()中的错误,使它能得出正确的结果。 注童:不要改动main函数,不得增行或删行,也不得更改程序的结构。 试题程序: #include <stdio.h> #include <string.h> #include <conio.h> char *fun (char tt[]) int i; for(i=0; tt[i]; i++) /**************found**************/ if(('A' <=tt[i]||(tt[i]<='z' )) tt[i]+=32; return(tt); main() int i; char tt[81]; clrscr(); printf("/nPlease enter a string:"); gets(tt); printf("/nThe result string is:/n %s", fun(tt));
问答题给定程序MODI1.C中函数fun的功能是:计算并输出high以内最大的10个素数之和。high的值由主函数传给fun函数。
若high的值为:100,则函数的值为:732。
请改正程序中的错误,使程序能输出正确的结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构!
#include
#include
int fun(int high)
{ int sum = 0, n=0, j, yes;
/************ found************/
while ((high >= 2)
for (j=2; j<=high/2; j++)
if (high % j ==0){
/************found************/
yes=0; break
}
if (yes) {sum +=high; n++;}
high--;
}
return sum ;
}
main ()
{
printf("%d/n", fun (100));
}
问答题请编写函数fun,函数的功能是查找x在s所指数组中下标的位置,并作为函数值返回,若x不存在,则返回-1。注意:部分源程序在文件PROG1.C文件中,请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。试题程序:#include<stdio.h>#include<stdlib.h>#define N 15 void NONO();int fun(int*s,int x){}main(){int a[N]={29,13,5,22,10,9,3,18,22,25,14,15,2,7,27),i,x,index; printf("a数组中的数据:\n"); for(i=0;i<N;i++) printf("%4 d",a[i]);printf("\n"); printf("给x输入待查找的数:"); scanf("%d",&x); index=fun(a,x); printf("index=%d\n",index); NONO(); } void NONO() {/*本函数用于打开文件,输入数据,调用函数,输出数据,关闭文件。*/ FILE*fp,*wf; int i,j,a[10],x,index; fp=fopen("in.dat","r"); wf=fopen("out.dat","w"); for(i=0;i<10;i++){ for(j=0;j<10;j++){ fscanf(fp,"%d",&a[j]); } fscanf(fp,"%d",&x); index=fun(a,x); fprintf(wf,"%d\n",index); } fclose(fp); fclose(wf); }
问答题下列给定程序中,函数fun的功能是:将s所指字符串中的字母转换为按字母序列的后续字母(如“Z”转化为“A”,“z”转化为“a”),其他字符不变。 请改正程序中的错误,使它能得出正确的结果。 注意:不要改动main函数,不得增行或删行,也不得更改程序的结构! 试题程序:{}include < stcllib.h >#include < stctio.h >#include < ctype.h >#include < conio.h >void fun(char*s){/*********found*********/ while(=*s!='@') { if(*s >='A'&&*s < ='Z'||*s >='a'&&*s < ='z') { if(*s=='z')*s='A'; else if(*s='z')*s='a'; else *s+=1; }/*********found*********/ (*s)++; }}void main(){ char s[80]; system("CLS"); printf("/n Enter a string withlength < 80:/n/n"); gets(s); printf("/n The string:/n/n"); putS(s); fun(s); printf("/n/n The Cords:/n/n"); puts(s);}
问答题请编写函数fun,其功能是:计算并输出下列多项式的值。例如,当n=10时,函数值为0.909091。注意:部分源程序在文件PROG1.C中。请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。试题程序:#include<conio.h>#include<stdio.h>#include<stdlib.h>doublefun(intn){}voidmain(){FILE*wf;system("CLS");printf("%f\n",fun(10));/******************/wf=fopen("out.dat","w");fprintf(wf,"%f",fun(10));fclose(wf);/******************/}
问答题下列给定的程序中,函数proc()的功能是:判断字符ch是否与str所指字符串中的某个字符相同;若相同,则什么也不做,若不同,则将其插在串的最后。
请修改程序中的错误,使它能得出正确的结果。
注意:不要改动main()函数,不得增行或删行,也不得更改程序的结构。
试题程序:
#include<stdlib.h>
#include<conio.h>
#include<stdio.h>
#include<string.h>
//****found****
void proc(char str, char ch)
{
while(*str
//****found****
if(*str==ch)
{str[0]=ch;
//****found****
str[1]="0";
}
}
void main()
{
char str[81], ch;
system("CLS");
printf("/nPlease enter a string: ");
gets(str);
printf("/n Please enter the character to
search: ");
ch=getchar();
proc(str, ch);
printr("/nThe result is %s/n", str);
}
问答题给定程序中,函数fun的功能是:
在任意给定的9个正整数中找出按升序排列时处于中间的数,将原数据序列中比该中间数小的数用该中间数替换,位置不变,在主函数中输出处理后的数据序列,并将中间数作为函数值返回。
例如,有9个正整数:
1 5 7 23 87 5 8 21 45
按升序排列时的中间数为:8
处理后主函数中输出的数列为:
8 8 8 23 87 8 821 45
请在程序的下画线处填入正确的内容并把下画线删除,使程序得出正确的结果。
注意:源程序存放在考生文件夹下的BLANKl. C中。不得增行或删行,也不得更改程序的结构!
试题程序:
#include < stdio.h >
#define N 9
int fun (int x[] )
{ int i, j , k, t,mid,b[N] ;
for (i =0;i < =N/2;i ++)
if (b[k] >b[j]) k =j;
{
/*********found*********/
t =b[i]; b[i] =
【1】
;
b[k]=t;
}
}
mid =b[
【2】
] ;
for(i=0;i < N;i++)
/*********found*********/
if (x[i]
【3】
mid) x[i] =mid;
}
return mid;
main ()
{ int i, x[N] = {1,5,7,23,87,5,
8,21,45 };
for(i=0;i < N;i++)
printf("%d ,x[i]);
printf "/nThe mid data is: %d/n",
fun(x));
printf ( " /n") ;
}
问答题请编写函数fun,该函数的功能是:删除一维数组中所有相同的数,使之只剩一个。数组中的数已按由小到大的顺序排列,函数返回删除后数组中数据的个数。例如,若一维数组中的数据是:2 2 2 3 4 4 5 6 6 6 6 7 7 8 9 9 10 10 10删除后,数组中的内容应该是:2 3 4 5 6 7 8 9 10注意:部分源程序给出如下。请勿改动主函数main和其他函数中的任何内容。仅在函数fun的花括号中填入你编写的若干语句。试题程序:#include<stdio.h>#define N 80int fun(int a[],int n){} void main() { int a[N]={2,2,2,3,4,4,5,6,6,6,6,7,7,8,9,9,10,10,10,10},i,n=20; printf("The original data:\n"); for(i=0;i<n;i++) printf("%3d",a[i]); n=fun(a,n); printf("\n\nThe data after deleted:\n"); for(i=0;i<n;i++) printf("%3d",a[i]); printf("\n\n");}
问答题给定程序MODI1.C中函数fun的功能是:从低位开始取出长整型变量s中奇数位上的数,依次构成一个新数放在t中。高位仍在高位,低位仍在低位。
例如,当s中的数为:7654321时,t中的数为:7531。
请改正程序中的错误,使它能得出正确的结果。
注意:不要改动mam函数,不得增行或删行,也不得更改程序的结构!
#include
void fun (long s. long t)
{ long s1=10;
*t= s% 10;
while (s> 0)
{ s= s/100;
*t= s%10 * s1 + *t;
s1= s1*100;
}
}
main ()
{ long s,t;
printf("/nPlease enter s:") f
scanf ("%1d",&S) ;
printf ("The result is: %ld/n",t) ;
}
问答题请编写函数fun,该函数的功能是:求出二维数组周边元素之和,作为函数值返回。二维数组中的值在主函数中赋予。例如,若二维数组中的值为:则函数值为61。注意:请勿改主动函数main和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。试题程序:#include<conio.h>#include<stdio.h>#include<stdlib.h>#defineM4#defineN5intfun(inta[M][N]){}voidmain(){FILE*wf;intaa[M][N]={{1,3,5,7,9},{2,9,9,9,4},{6,9,9,9,8},{1,3,5,7,0}};inti,j,y;system("CLS");printf("Theoriginaldatais:/n");for(i=0;i<M;i++){for(j=0;j<N;j++)printf("%6d",aa[i][j]);printf("/n");}y=fun(aa);printf("/nThesun:%d/n",y);printf("/n");/******************/wf=fopen("out.dat","w");fprintf(wf,"%d",y);fclose(wf);/******************/}
问答题给定程序中,函数fun的功能是:将不带头结点的单向链表结点数据域中的数据从小到大排序。即若原链表结点数据域从头至尾的数据为10,4、2、8、6,排序后链表结点数据域从头至尾的数据为2、4、6、8、10。
请在程序的下画线处填入正确的内容并把下画线删除,使程序得出正确的结果。
注意:部分源程序给出如下。
不得增行或删行,也不得更改程序的结构!
试题程序:
#include<stdio.h>
#include<stdlib.h>
#define N 6
typedef struct node{
int data;
struct node*next;
}NODE;
void fun(NODE*h)
{ NODE*p,*q;int t ;
p=h;
while(P){
/*********found*********/
q=
【1】
;
/*********found*********/
while(
【2】
)
{if(P->data>q->data)
{t=P->data;
P->data=q->data ;
q->data=t;)
q=q->next;
}
/*********found*********/
p=
【3】
;
}
}
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]={0,10,4,2,8,6);
head=creatlist(a);
printf("\nThe original list:\n");
outlist(head);
fun(head);
printf("\nThe list after inverting:\n");
outlist(head);
}
问答题请编写一个函数proc(),它的功能是将一个数字字符书转换为一个整数(不得调用C语言提供的将字符串转为整数的函数)。
例如,若输入字符串“1234”,则函数把它转换为整数值1234。
注意:部分源程序给出如下。
请勿改动main()函数和其他函数中的任何内容,仅在函数proc()的花括号中填入所编写的若干语句。
试题程序:
#include<stdio.h>
#include<string.h>
long proc(char*p)
{
}
void main()
{
char str[6];
long n;
printf("Enter a string:/n");
gets(str);
n=proc(str);
printf("%1d/n", n);
}
问答题下列给定程序中,函数fun的功能是计算下式直到≤10一3,并将计算结果作为函数值返回。例如,若形参e的值为le一3,函数的返回值为2.985678。请在程序的下画线处填入正确的内容并将下画线删除,使程序得出正确的结果。注意:部分源程序给出如下。不得增行或删行,也不得更改程序的结构!试题程序:#include<stdio.h>doublefun(doublee){inti;doubles,x;/*********found*********/s=o;i=【1】;x=1.0;while(x>e){/*********found*********/【2】;/*********found*********/x=(2.0,*i一1)/((—[【3】),*(2.0*i));s=s+x;}Eeturns;}main(){doublee=1e一3;print:f("/nTheresultis:%f/n",fun(e));}
问答题下列给定程序中,函数fun的功能是:用递归算法计算斐波拉契数列中第n项的值。从第1项起,斐波拉契数列为:1,1,2,3,5,8,13,21,… 例如,若给n输入7,则该项的斐波拉契数值为13。 请改正程序中的错误,使它能得出正确结果。 注意:不要改动main函数,不得增行或删行,也不得更改程序的结构! 试题程序: #include<stdio.h> long fun(int g) /********found********/ switch(g); case oreturn 0; /********found********/ case 1;case 2;return 1; return(fun(g-1)+fun(g-2)); void main() long fib;int n; printf("Input n:"); scanf("%d". printf("n=%d/n",n); fib=fun(n); printf("fib=%d/n/n",fib);
问答题学生的记录由学号和成绩组成,N名学生的数据已在主函数中放入结构体数组s中,请编写函数劬,它的功能是:把高于等于平均分的学生数据放在b所指的数组中,高于等于平均分的学生人数通过形参n传回,平均分通过函数值返回。
注意:部分源程序在文件PROG1.C文件中。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。
#include
#define N 12
typedef struct
{ char num [10] ;
double s;
} STREC;
double fun(STREC *a,STREC *b,int
*n)
{
}
main ( )
{STREC s ENJ ={ { "GA05",85},{ "GA03",76},
{ "GA02",69},{ "GA04",85},{ "GA01",91} ,
{ "GA07",72},{"GA08",64 },{"GA06",87} ,
{ "GA09",60},{ "GA11",79},{ "GA12 ",73},
{ "GA10",90} };
STREC h[N],t;FILE *out ;
int i,j,n; double ave;
ave=fun (s,h,&n) ;
printf ( "The %d student data which
is higher than o07.3f:/n",n,ave);
printf (" %s %4 .1f/n",h [i] .num,
printf ( "/n") ;
out =fopen ("out.dat","w") ;
fprintf ( out, " %d/no0 7 . 3f/nl' ,n,ave) ;
for (i=0; i