问答题给定程序中,函数fun的功能是:
统计形参s所指的字符串中数字字符出现的次数,并存放在形参t所指的变量中,最后在主函数中输出。
例如,若形参s所指的字符串为“abcdef35adgh3kjsdf7”,则输出结果为4。
请在程序的下画线处填入正确内容并将下画线删除,使程序得出正确的结果。
注意:部分源程序给出如下。
不得增行或删行,也不得更改程序的结构!
试题程序:
#include < stdio.h >
void fun(char*s,int*t)
{ int i,n;
n=0;
/*********found*********/
for(i=0;
【1】
!=0;i++)
/*********found*********/
if(s[i] >='0'&&s[i] <
【2】
)
n++;
/*********found*********/
【3】
;
}
main()
{char s[80]="abcdef35adih3kjsdf7";
int t;
printf("/nThe original
string is:%s/n",s);
fun(s,&t);
printf("/nThe result is:%d/n",t);
}
问答题N名学生的成绩已在主函数中放入一个带头结点的链表结构中,h指向链表的头结点。请编写函数fun,其功能是:求出平均分,并由函数值返回。 例如,若学生的成绩是:85,76,69,85,91,72,64,87,则平均分应当是:78.625。 注意:部分源程序给出如下。 请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。 试题程序:#include < stdlib.h >#include < stdio.h >#define N 8stELI* s1ist{ double s; Struct s1ist * next;};typeclef struct s1ist STREC;double fun(STREC* h){}STREC*creat(double*s)/*建链表*/{ STREC * h,*p,*q; int i=0; h=p=(STREC*)malloc(sizeof(STREC)); p一 >s=0; while(i < N) { q=(STREC*)malloc(sizeof(STREC)); q一 >s=s[i];i++;p一 >next=q;p=q; } p一 >next=0; return h; } outlist(STREC*h) { STREC*p; p=h一 >next; printf("head"); do { printf("一 >%4.1 f",p一 >s); p=p一 >next;/*输出各成绩*/ }while(p!=NULL); printf("/n/n");}void main(){ double s[N]={8 5,7 6,6 9,85,91,72,64,87},ave; STREC* h; h=creat(s);outlist(h); ave=fun(h); printf("ave=%6.3 f/n",ave);}
问答题学生的记录由学号和成绩组成,N名学生的数据已在主函数中放入结构体数组s中,请编写函数fun,它的功能是:函数返回指定学号的学生数据,指定的学号在主函数中输入。若没找到指定学号,在结构体变量中给学号置空串,给成绩置-1,作为函数值返回。(用于字符串比较的函数是strcmp)。 注意:部分源程序在文件PROG1.C中。 请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。1 #include<stdio.h>2 #include<string.h>3 #define N 164 typedef struct5 { char num[10];6 int s;7 } STREC;8 STREC fun(STREC *a,char *b)9 {1011 }12 main()13 { STREC s[N]={{''GA005'',85},{''GA003'',76},{''GA002'',69},{''A004'',85},{''GA001'',91},{''GA007'',72},{''GA008'',64},{''GA006'',87},{''GA015'',85},{''GA013'',91},{''GA012'',64},{''GA014'',91},{''GA011'',77},{''GA017'',64},(''GA018'',64},{''GA016'',72}};14 STREC h;15 char m[10];16 int i;FILE *out;17 printf(''The original data:\n'');18 for(2=0;i<N;i++)19 { if(i%4==0) printf(''\n'');20 printf(''%s%3d'',s[i].num,s[i].s);21 }22 printf(''\n\nEnter the number: '');gets(m);23 h=fun(s,m);24 printf(''The data:'');25 printf(''\n%s %4d\n'',h.num,h.s);26 printf(''\n'');27 out=fopen(''out.dat'',''w'');28 h=fun{s,''GA013''};29 fprintf(out,''%4d\n'',h.num,h.s);30 fclose(out);31 }
问答题请编写函数fun(),它的功能是:将带头结点单向链表按data域由大到小排序(排序时不考虑头结点),主函数用随机函数为各节点data域赋值,头结点data域赋值为0。 [注意] 部分源程序给出如下。 请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。 [试题源程序] #include <stdio.h> #include<coni0.h> struct as int data; struct aa *next; ; void fun(struct aa *p) main() int i, n, m=100; struct aa *h=NULL, *s=NULL, *p=NULL; clrscr() s=(struct aa*) malloc(siZeof(struct aa)); h=s; h->data=0; h->next=NULL; printf("Please input n:"); scanf("%d", &n); for(i=1; i<=n; i++) p=(struct aa*) malloc(sizeof(struct aa)); p->data=rand()%m; P->next=NULL; printf("%d", P->data); s->next=p; s=s->next; fun(h); printf("/n"); for(h=h->next; h!=NULL; h=h->nnext) printf("%d", h->data);
问答题给定程序的主函数中,已给出由结构体构成的链表结点a、b、c,各结点的数据域中均存入字符,函数fun()的作用是:将a、b、c三个结点链接成一个单向链表,并输出链表结点中的数据。
请在程序的下画线处填入正确的内容并把下画线删除,使程序得出正确的结果。
注意:源程序存放在考生文件夹下的BLANK1.C中。不得增行或删行,也不得更改程序的结构!
试题程序:
#include<stdio.h>
typedef struct list
{ char data;
struct list*next;
}Q;
void fun(Q*pa,Q*pb,Q*pc)
{Q*P;
/*********found*********/
pa->next=
【1】
;
pb->next=pc;
p=pa;
while(P)
{
/*********found*********/
printf("%c",
【2】
);
/*********found*********/
p=
【3】
;
}
printf("\n");
}
main()
{ Q a,b,c;
a.data='E';b.data='F';
c.data='G'; c.next=NULL;
fun(&a,&b,&c);
}
问答题请编写函数proc(),它的功能是计算下列级数和,和值由函数值返回。
sum=1-x+x2/2!-x3/3!+…+(-1*x)n/n!
例如,当n=23,x=0.3时,函数值为0.740818。
注意:部分源程序给出如下。
请勿改动main()函数和其他函数中的任何内容,仅在函数proc()的花括号中填入所编写的若干语句。
试题程序:
#include<stdlib.h>
#include<conio.h>
#include<stdio.h>
#include<math.h>
double proc(double x, int n)
{
}
void main()
{
system("CLS");
printf("%f", proc(0.3, 23));
}
问答题给定程序MODI1.C中函数 fun 的功能是:统计字符串中各元音字母(即:A、E、I、O、U)的个数。注意:字母不分大、小写。
例如:若输入:THIs is a boot,则输出应该是:1、0、2、2、0。
请改正程序中的错误,使它能得出正确的结果。
注意:不要改动 main 函数,不得增行或删行,也不得更改程序的结构!
给定源程序:
#include
fun ( char *s, int num[5] )
{ int k, i=5;
for ( k = 0; k
/**********found**********/
num[i]=0;
for (; *s; s++)
{ i = -1;
/**********found**********/
switch ( s )
{ case 'a': case 'A': {i=0; break;}
case 'e': case 'E': {i=1; break;}
case 'i': case 'I': {i=2; break;}
case 'o': case 'O': {i=3; break;}
case 'u': case 'U': {i=4; break;}
}
if (i >= 0)
num[i]++;
}
}
main( )
{ char s1[81]; int num1[5], i;
printf( "/nPlease enter a string: " ); gets( s1 );
fun ( s1, num1 );
for ( i=0; i < 5; i++ ) printf ("%d ",num1[i]); printf ("/n");
}
问答题学生记录由学号和成绩组成,N名学生的数据已放入主函数中的结构体数组中,请编写函数fun,其功能是:把分数最低的学生数据放入b所指的数组中。注意:分数最低的学生可能不止一个,函数返回分数最低的学生人数。
注意
:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。
试题程序:
#include<stdio.h>
#define N 16
typedef struct
{char num[10];
int s;
}STREC;
int fun(STREC *a,STREC *b)
{
}
main()
{
STREC s[N]={{"GA05",85},{"GA03",76},{"GA02",59},{"GA04",85},
{"GA01",91},{"GA07",72},{"GA08",64},{"GA06",87},
{"GA015",85},{"GA013",91},{"GA012",64},{"GA014",91},
{"GA011",91},{"GA017",64},{"GA018",64},{"GA016",72}};
STREC h[N];
int i, n; FILE *out;
int i,n;
n=fun(s,h);
printf("The %d lowest score:/n",n);
for(i=0;i<n;i++)
printf("%s %4d/n",h[i].num,h[i].s);
printf("/n");
out=fopen("out,dat","w");
fprintf out, "%drn",n);
forli=0;i(n;i++)
fprintf(out,"%40||n",h[i],s);
fclose(out);
}
问答题函数fun的功能是:将a、b中的两个两位正整数合并形成一个新的整数放在c中。合并的方式是:将a中的十位和个位数依次放在变量c的千位和十位上,b中的十位和个位数依次放在变量c的个位和百位上。
例如,当a=45,b=12,调用该函数后,c=4251。
注意:部分源程序存在文件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);
}
问答题编写函数,把数组中所有奇数放在另一个数组中返回。
问答题给定程序MODI1.C中函数fun的功能是:将s所指字符串的正序和反序进行连接,形成一个新串放在t所指的数组中。
例如,当s所指字符串为:“ABCD”时,则t所指字符串中的内容应为:“ABCDDCBA”。
请改正程序中的错误,使它能得出正确的结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构!
给定源程序:
#include <stdio.h>
#include <string.h>
/************found************/
void fun(char s,char t)
{
int i,d;
d=strlen(s);
for(i=0;i<d;i++) t[i]=s[i];
for(i=0;i<d;i++) t[d+i]=s[d-1-i];
/************found************/
t[2*d-1]="/0";
}
main()
{
char s[100],t[100];
printf("/nPlease enter string s:");
scanf("%s",s);
fun(s,t);
printf("/nThe result is:%s/n",t);
}
问答题给定程序MODI1.C中函数fun的功能是:计算函数(x,y,z)=(x+y)/(x-y)+(z+y)/(z-y)的值。其中x和y的值不等,z和Y的值不等。例如,当x的值为9、y的值为11、z的值为15时,函数值为-3.50。 请改正程序中的错误,使它能得出正确结果。 注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。1 #include<stdio.h>2 #include<math.h>3 #include<stdlib.h>4 /**********found**********/5 #define FU(m,n) (m/n)6 float fun(float a,float b, float c)7 { float value ;8 value=FU(a+b,a-b)+FU(c+b,c-b);9 /**********found**********/10 Return(Value);11 }12 main()13 { float x,y,z,sum;14 printf(''Input x y z:'');15 scanf(''%f%f%f'',&x,&y,17 if(x==y || y==z){printf(''Data error!\n''); exit(0);}18 sum=fun(x,y,z);19 printf(''The result is:%5.2f\n'',sum);20 }
问答题编写函数fun,其功能是:求ss所指字符串中指定字符的个数,并返回此值。例如,若输入字符串123412132,输入字符为1,则输出3。注意:部分源程序在文件PROG1.C中。请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。#inelude<stdio.h>#include<string.h>#defineM81int fun(char*ss,char c){}main(){char a[M],ch;void NONO();printf("\nPlease enter a string:");gets(a);printf("\nPlease enter a char:");ch=getehar();printf("\nThe number of the char is:%d\n",fun(a,ch));NONO();}void NONO(){/*本函数用于打开文件,输入测试数据,调用fun函数,输出数据,关闭文件。*/int i;FILE*rf,*wf;char a[M],b[M],ch;rf=fopen("in.dat","r");wf=fopen("out.dat","w");for(i=0;i<10;i++){facnf(rf,"%s",a);fscanf(rf,"%s",b);ch=*b;fprintf(wf,"%c=%d\n",ch,fun(a,ch));}felose(rf);fclose(wf);}
问答题请编写函数void proc(char a[],charb[],int n),其功能是:删除一个字符串中指定下标的字符。其中,a指向原字符串,删除后的字符串存放在b所指的数组中,n中存放指定的下标。
例如,输入一个字符串thanyou,然后输入4,则调用该函数后的结果为thanyou。
注意:部分源程序给出如下。
请勿改动main()函数和其他函数中的任何内容,仅在函数fun()的花括号中填入所编写的若干语句。
试题程序:
#include<stdlib.h>
#include<stdio.h>
#include<conio.h>
#define N 20
void proc(char a[],char b[],int n)
{
}
void main()
{
char str1[N],str2[N];
int n;
system("CLS");
printf("Enter the string:/n");
gets(str1);
printf("Enter the position of the string deleted:");
scanf("%d",
proc(str1,str2,n);
printf("The new string is:%s/n",str2);
}
问答题编写函数fun,其功能是:实现两个字符串的连接(不要使用库函数strcat),即把p2所指的字符串连接到p1所指的字符串的后面。 例如,分别输入下面两个字符串: “FirstString一一” “SecondString” 程序输出: “FirstString一一SecondString” 注意:部分源程序给出如下。 请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。 试题程序:#include < stdlib.h >#include < stdio.h >#include < conio.h >void fun(char p1[],char p2[]){}void main(){ char s1[80],s2[40], system("CLS"); printf("Enter s1 and s2:、n"); scanf("%S%s",s1,s2); printf("s1=%s/n",s1); printf("s2=%s/n",s2); printf("Invoke fun(s1,s2):/n"); fun(s1,s2); printf ("After invoking:/n"); printf("%S/n",s1);}
问答题给定程序中,函数fun的功能是:计算出形参S所指字符串中包含的单词个数,作为函数值返回。为便于统计,规定各单词之间用空格隔开。
例如,形参s所指的字符串为:This is a C language program.,函数的返回值为6。
请在程序的下划线处填入正确的内容并把下划线删除,使程序得出正确的结果。
注意:源程序存放在
下的BLANK1.C中。
不得增行或删行,也不得更改程序的结构!
#include <stdio.h>
int fun(char *s)
{ int n=0,flag=0;
while(*s!="/0")
{ if(*s!=" " flag=1;}
/**********found**********/
if(*s==" ")flag=______;
/**********found**********/
______;
}
return n;
}
main()
{ char str[81]; int n;
printf("/nEnter a line text:/n");gets(str);
n=fun(str);
printf("/nThere are %d words in this text./n/n",n);
}
问答题函数fun的功能是:读入一个字符串(长度<20),将该字符串中的所有字符按ASCII码升序排序后输出。 例如,若输入:edcba,则应输出:abcde。 请改正程序中的错误,使它能得到正确结果。 注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。 [试题源程序] #include<stdio.h> void fun(char t[]) Char c; int i,j; /**********found***********/ for(i=strlen(t);i;i--) for(j=0;j<i;j++) /**********found***********/ if(t[j]<t[j+1]) c=[j]; t[j]=t[j+1]; t[j+1]=c; main() char s[81]; printf("/nPlease enter a character string:"); gets(s); printf("/n/nBefore sorting:n/"%s/"",s); fun(s); printf("/nAfter sorting decendingly:/n/"%s/"",s);
问答题下列给定程序中,函数fun的功能是:删除指针P所指字符串中的所有空白字符(包括制表符、回车符及换行符)。输入字符串时用“#”结束输入。请改正程序中的错误,使它能输出正确的结果。注意:不要改动main函数,不得增行或删行,也不得更改程序的结构!试题程序:#includee<string.h>#includee<stdio.h>#includee<ctype.h>fun(char*P){ int i,t;char c[80];/*********found*********/ For(i=0,t=0;P[i];i++) if(!isspace(*(p+i))) c[t++]=P[i];/*********found*********/ c[t]="\0"; strcpy(p,c);} void main(){ char c,s[80], int i=0; printf("Input a string:"); c=getchar(); while(c!='#') {s[i]=c;i++;c=getchar();) S[i]='\0'; fun(s); puts(s),}
问答题编写函数fun,其功能是:将所有大于1小于整数m的非素数存入xx所指数组中,非素数的个数通过k返回。例如,若输入17,则应输出:4 6 8 9 10 12 14 15 16。注意:部分源程序在文件PROG1.C中。请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。#include<stdio.h>void fun(int m,int*k,int xx[]){}main(){ int m,n,zz[100];void NONO(); printf(''\nPlease enter an integer number between 10 and 100:'');scanf(''%d'',&n)fun(n,&m,zz);prinff(''\n\nThere are%d non—prime numbers less than%d:'',m,n);for(n=0;n<m;n++)printf(''\n%4d'',zz[n]);NONO();}void NONO(){/*请在此函数内打开文件,输入测试数据,调用fun函数,输出数据,关闭文件。*/int m,n,zz[100];FILE*rf,*wf;rf=fopen(''in.dat'',''r'');Wf=fopen(''out.dat'',''w'');fscanf(rf,''%dt,&n);fun(n,&m,zz);fprintf(wf,''%d\n%d\n'',m,n);for(n=0;n<m;n++)fprintf(wf,''%dkn'',zz[n]);fclose(rf);fclose(wf);}
问答题下列给定程序中,函数fun的功能是:把形参s所指字符串中下标为奇数的字符右移到下一个奇数位置,最右边被移出字符串的字符绕回放到第一个奇数位置,下标为偶数的字符不动(注意:字符串的长度大于等于2)。 例如,形参s所指字符串为“abcdefah”,执行结果为“ahcbedaf”。 请在下划线处填入正确的内容并将下划线删除,使程序得出正确的结果。 注意:部分源程序给出如下。 不得增行或删行,也不得更改程序的结构! 试题程序: #include<stdio.h> void fun(char*s) int i,n,k; char c; n=0; for(i=0;s[1]='/0';i++) n++, if(n%2=0) /********found********/ k=n- (1) ; else k=n-2; /********found********/ c= (2) ; for(i=k-2;i>=1;i=i-2) (s[i+2]=s[i]; /********found********/ s[1]= (3) ;) main() char s[80]="abcdefgh"; printf("/nThe original string is:%s/n",s); fun(s); printf("/nThe result is:%s/n",s);