问答题下列给定的程序中,函数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
问答题请编函数fun,其功能是将一个数字字符串转换成与其面值相同的长整型整数。可调用strlen函数求字符串的长度。例如:在键盘输入字符串2345210,函数返回长整型数2345210。注意:部分源程序存在PROG1.C中,请勿改动主函数main和其他函数中的任何内容,仅在函数fun指定的部位填入所编写的若干语句。试题程序:#include<stdio.h>#include<string.h>void NONO();long fun(char*s){}main(){ char s[10];long r; printf("请输入一个长度不超过9个字符的数字字符串:"); gets(s); r=fun(s); printf("r=%ld\n",r); NONO();}void NONO()(/*本函数用于打开文件,输入数据,调用函数,输出数据,关闭文件。*/ FILE* fp,*wf; int i;long r; Char s[10],*p; fp=fopen("in.dat","r"); wf=fopen("out.dat","w"); for(i=0;i<10;i++){ fgets(s,10,fP); P=strchr(s,'\n'); if(p)*p=0; r=fun(s); fprintf(wf,"%ld\n",r); } fclose(fp); fclose(wf);}
问答题下列给定程序中,函数fun的功能是:将形参s所指字符串中下标为奇数的字符按ASCII码大小递增排序,并将排序后下标为奇数的字符取出,存入形参P所指字符数组中,形成一个新串。
例如,形参s所指的字符为“baawrskjghzlicda”,执行后P所指字符数组中的字符串应为“aachjlsw”。
请在程序的下画线处填入正确的内容并将下画线删除,使程序得出正确的结果。
注意:部分源程序给出如下。
不得增行或删行,也不得更改程序的结构!
试题程序:
#include<stdio.h>
void fun(char*s,char*p)
{ int i,j,n,x,t;
n=0;
for(i=0;s[i]!='\0';i++)n++;
for(i=1;i<n-2;i=i+2){
/*********found*********/
【1】
;
/*********found*********/
for(j=
【2】
+2;j<n;j=j+2)
if(s[t]>s[j])t=j;
if(t!=i)
{x=s[i];s[i]=s[t];s[t]=x;}
}
for(i=1,j=0;i<n;i=i+2,j++)
P[j]=S[i];
/*********found*********/
P[j]=
【3】
;
}
main()
{ char s[80]="baawrskj ghzlicda",P[50];
printf("\nThe original string is:%s\n",s);
fun(s,P);
printf("\nThe result is:%s\n",p);
}
问答题下列给定程序中,函数fun的功能是:将N×N矩阵中元素的值按列向右移动1个位置,右边被移出矩阵的元素绕回左边第1列。 例如,N=3,有下列矩阵: 1 2 3 …… 4 5 6 …… 7 8 9 计算结果为: 3 1 2 …… 6 4 5 …… 9 7 8 请在下划线处填入正确的内容并将下划线删除,使程序得出正确的结果。 注意:部分源程序给出如下。 不得增行或删行,也不得更改程序的结构! 试题程序: #include<stdio.h> #define N 4 void fun(intI*t)[N1) int i,j,x; /********found********/ for(i=0;i< (1) ;i++) /********found********/ x=f[i] (2) ]; for(j=N-1;j>0;j--) t[i][j]=t[i][j-1]; /********found********/ f[i][ (3) ]=x; main() int t[][N]=21,12,13,24,25,16,47,38,29,11,32,54,42,21,33,10,i,j; printf("The original array;/n"); for(i=0;i<N;i++) for(j=0;j<N;j++) printf("%2d",t[i][j]); printf("/n"); fun(t); printf("/nThe result is:/n"); for(i=0;i<N;i++) for(j=0;j<N;j++) printf("%2d",t[i][j]); printf("/n");
问答题请编写函数fun,其功能是:移动一维数组中的内容,若数组中有n个整数,要求把下标从0~P(含P,P小于等于n—1)的数组元素平移到数组的最后。例如,一维数组中的原始内容为:1、2、3、4、5、6、7、8、9、10;P的值为3。移动后,一维数组中的内容应为:5、6、7、8、9、10、1、2、3、4。注意:部分源程序给出如下。请勿改动主函数main和其他函数中的内容,仅在函数fun的花括号中填入你编写的若干语句。试题程序:#include<stdio.h>#define N 80void fun(int*w,int p,int n){}main(){ int a[N]={1,2,3,4,5,6,7,8,9,1 0,11,12,13,14,15); int i,P,n=15; printf("The original data:\n"); for(i=0;i<n;i++) printf("%3d",a[i]); printf("\n\nEnter P:"); scanf("%d",&p); fun(a,P,n); printf("\nThe data after mouing:\n"); for(i=0 ; i<n; i++) printf("%3 d",a[i]); printf("\n\n");}
问答题给定程序MODI1.C中fun函数的功能是:将n个无序整数从小到大排序。请改正程序中的错误,使它能得出正确的结果。注意:不要改动main函数,不得增行或删行,也不得更改程序的结构!给定源程序:
问答题函数fun的功能是:将两个两位数的正整数a、b合并形成一个整数放在c中。
合并的方式是:将a数的十位和个位数依次放在c数的个位和百位上,b数的十位和个位数依次放在c数的十位和千位上。
例如,当a=45,b=12时,调用该函数后,c=2514。
注意:部分源程序存在文件PROG1.C中。数据文件in.dat中的数据不得修改。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入要编写的若干语句。
#include<stdio.h>
void fun(int a,int b,long*c)
{
}
main()
{int a,b;long c;
void NONO();
printf("Input a,b:");
scanf("%d,%d",
fun(a,b,
printf("The result is:%1d/n",c);
NONO();
}
void NONO()
{/*本函数用于打开文件,输入数据,调用函数,输出数据,关闭文件。*/
FILE*rf,*wf;
int i,a,b;long c;
rf=fopen("in.dat","r");
wf=fopen("out.daft,"w");
for(i=0;i<10;i++){
fscanf(rf,"%d,%d",
fun(a,b,
fprintf(wf,"a=%d,b=%d,c=%1d/n",a,b,c);
}
fclose(rf);
fclose(wf);
}
问答题请编写函数fun,其功能是:将放在字符串数组中的M个字符串(每串的长度不超过N),按顺序合并组成一个新的字符串。
例如,若字符串数组中的M个字符串为{"AAAA", "BBBBBBB", "CC"},则合并后的字符串内容应该是“AAAABBBBBBBCC”。
注意
:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。
试题程序:
#include<stdio.h>
#include<conio.h>
#define M 3
#define N 20
void fun(char a[M][N],char *b)
{
}
void main()
{
char w[M][N]={"AAAA","BBBBBBB","CC"},i;
char a[100]={"##################"};
printf("The string:/n");
for(i=0;i<M;i++)
puts(w[i]);
printf("/n");
fun(w,a);
printf("The A string:/n");
printf("%s",a);
printf("/n/n");
}
问答题下列给定程序中函数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, num2, a;
printf("Input num1 num2: "); scanf("% d% d", printf("num1 =% d num2=% d/n/n", num1,
num2); a=fun(num1, num2); printf("The maximun
common divisor is% d/n/n", a); }
问答题请编写一个函数fun,它的功能是:找出一维整型数组元素中最大的值和它所在的下标,最大的值和它所在的下标通过形参传回。数组元素中的值已在主函数中赋予。 主函数中X是数组名,n是x中的数据个数,max存放最大值,index存放最大值所在元素的下标。注意:部分源程序存在文件PROGl.C文件中。请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。 #include<stdlib.h> #include<stdio.h> void fun(int a[],int n,int*max,int*d) { } main() {int i,x[20],max,index,n=10;void NONO (); for(i=0;i<n;i++){x刚=rand()%50;printf("%4d",x[i]);} printf("\n"); fun(x,n,&max,&index); printf("Max=%5d,Index=%4d\n",max,index); NONO();} void NONO() {/*本函数用于打开文件,输入数据,调用函数,输出数据,关闭文件。*/ FILE*fp,*wf; int i,x[20],max,index,n=10,j; fp=fopen("in.dat","r"); wf=fopen("out.dat","w"); for(i=0;i<10;i++){ for(j=0;j<n;j++)fscanf(fp,"%d,",&x[j]); fun(x,n,&max,&index); fprmtf(wf,"Max=%d,Index=%d\n”,max,index); } fclose(fp); fclose(wf);}
问答题请编写一个函数fun,它的功能是:将ss所指字符串中所有下标为奇数位置上的字母转换成大写(若该位置上不是字母,则不转换)。 例如:若输入“abe4Efg”,则应输出“aBc4EFg”。 注意:部分源程序在文件PROG1.C中。 请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。 文件PROG1.C内容如下: #include<stdio.h> #include<string.h> void fun ( char *ss ) void main ( ) char tt[81] ; printf("/nPlease enter an string within 80 characters: /n" ) ; gets( tt ) ; printf( " /n/nAfter changing, the string/n /" % s/ , tt ) ; fun( tt ) ; printf( " /nbecomes/n /"% s/"/n" , tt) ;
