问答题给定程序中,函数fun的功能是:将形参指针所指结构体数组中的三个元素按num成员进行升序排列。
请在程序的下划线处填入正确的内容并把下划线删除,使程序得出正确的结果。
注意:源程序存放在考生文件夹下的BLANK1.C中。不得增行或删行,也不得更改程序的结构!
给定源程序:
#include
typedef struct
{ int num;
char name[10];
}PERSON;
/**********found**********/
void fun(PERSON ___1___)
{
/**********found**********/
___2___ temp;
if(std[0].num>std[1].num)
{ temp=std[0]; std[0]=std[1]; std[1]=temp; }
if(std[0].num>std[2].num)
{ temp=std[0]; std[0]=std[2]; std[2]=temp; }
if(std[1].num>std[2].num)
{ temp=std[1]; std[1]=std[2]; std[2]=temp; }
}
main()
{ PERSON std[ ]={ 5,"Zhanghu",2,"WangLi",6,"LinMin" };
int i;
/**********found**********/
fun(___3___);
printf("/nThe result is :/n");
for(i=0; i<3; i++)
printf("%d,%s/n",std[i].num,std[i].name);
}
问答题下列给定程序中,函数fun的功能是:根据整数形参m的值,计算如下公式的值。例如,若m中的值为5,则应输出0.536389。请改正程序中的错误,使它能得出正确的结果。注意:不要改动main函数,不得增行或删行,也不得更改程序的结构!试题程序:#include<stdio.h>doublefun(intm){doubley=1.0;inti;/********found********/for(i=2;i<m;i++)/********found********/y-=1/(i*i);return(y);}main(){intn=5;printf("/nTheresultis%lf/n",fun(n));}
问答题给定程序MODI1.C中函数fun的功能是:从n(形参)个学生的成绩中统计出低于平均分的学生人数,此人数由函数值返回,平均分存放在形参aver所指的存储单元中。
例如,若输入8名学生的成绩:
80.5 60 72 90.5 98 51.5 88 64
则低于平均分的学生人数为:4(平均分为:75.5625)。
请改正程序中的错误,使它能统计出正确的结果。
注意:不要改动main函数,不得增行或删行,也不得更改程序的结构!
#include
#define N 20
int fun (float *s,int n,float
*aver)
{ float ave,t =0.0 ;
int count = 0,k,i ;
t = s[k];
ave — t / n ;
if (s[i] < ave) count++ ;
*aver = Ave ;
return count ;
}
main ()
{ float s[30],aver ;
int m,i ;
printf ("/nPlease enter m: ") ;
scanf ( " %d", &m) ;
printf ("/nPlease enter %d mark:
for(i = 0 ; i < m ; i++) scanf
printf ("/nThe number of
students: %d /n", fun (s, m.
printf (t'Ave = %f/n", aver) ;
}
问答题(补充每对/**/之间的程序段,完成题目的要求)
问答题请编写函数fun(),该函数的功能是:统计各年龄段的人数。N个年龄通过调用随机函数获得,并放在主函数的age数组中。要求函数把0至9岁年龄段的人数在d[0]中,把10至19岁年龄段的人数放在d[1]中,把20至29岁年龄段的人数放在 d[2]中,依次类推,把100岁(含100)以上年龄的人数都放在d[10]中。结果在主函数中输出。 注意:部分源程序给出如下。 请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。 试题程序: #include <stdio. h> # define N 50 # define M 11 void fun(int *a, int *b) double rnd() static t=29, c=217,m=1024, r=0; r= (r*t+c)%m; return ((double) r/m); main ( ) int age[N], i,d[M]; for(i=0; i<N; i++) age [i]= (int) (i15*rnd ()); /*产生一个随机的年龄数组*/ printf ("The original data : /n"); for(i=0; i<N; i++) printf((i+l)%10= =07 "%4d/n":"%4d", age[i]); /*每行输出10个数* / printf ("/n/n"); fun (age, d); for(i=0; i<l0; i++) printf("%4d---%4d :%4d/n", i*l0, i*10+9, d[i] ); printf("Over 100 : %4dkn",d[10]).;
问答题请编写函数fun,该函数的功能是:将S所指字符串中ASCⅡ码值为偶数的字符删除,串中剩余字符形成一个新串放在t所指的数组中。 例如,若s所指字符串中的内容为“ABCDEFGl2345”,其中字符B的ASCⅡ码值为偶数,字符2的ASCⅡ码值为偶数,都应当删除,其他依此类推。最后t所指的数组中的内容应是”ACEG135”。 注意:请勿改动main函数和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。 试题程序:#include<stdio.h>#include<string.h>#include<conio.h>#include<stdlib.h>void fun(char * s,char t[]){}void main(){ FILE*wf; char S[100],t[100]; system(“CLS”); prinff(“\nPlease enter string S:”); scanf(“%s”,s); fun(s,t); printf(“\nThe result is:%s\n”,t);/*****************/ wf=fopen(“out.dat”,”W”); fun(“ABCDEFGl2345”,t); fprinff(wf,“%S”,t); fclose(wf);/*****************/
问答题学生的记录由学号和成绩组成,N名学生的数据已在主函数中放入结构体数组s中,请编写函数fun,它的功能是:把低于平均分的学生数据放在b所指的数组中,低于平均分的学生人数通过形参n传回,平均分通过函数值返回。
注意:部分源程序在文件PROG1.C中。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。
#include
#define N 8
typedef struct
{ char num[10];
double s;
} STREC;
double fun(STREC *a,STREC *b,int
*n)
{
}
main ()
{STREC s[N]={{"GA05",85},
{"GA03",76},{"GA02",69},{"GA04",85
},{"GA01",91},{"GA07",72},{"GA08",
64},{"GA06",87}};
STREC h[N],t;FILE *out ;
int i,j,n; double ave;
ave=fun(s,h,
printf("The %d student data which
is lower than %7.3f:/n",n,ave);
for(i=0;ih[j].s)
{t=h[i];h[i]=h[j];h[j]=t;}
for(i=0;i
问答题编写函数fun,其功能是:根据以下公式求P的值,结果由函数值带回。m与n为两个正整数且要求m>n。例如:m=12,n=8时,运行结果为495.000000。注意:部分源程序在文件PROG1.C中。请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。试题程序:#include<stdio.h>floatfun(intm,intn){}main()/*主函数*/{voidNONO();printf("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的功能是:计算s=f(-n)+f(-n+1)+…+f(0)+f(1)+f(2)+…+f(n)的值。例如,当n的值为5时,函数值应为10407143。f(x)函数定义如下:请改正程序中的错误,使它能得出正确的结果。注意:不要改动main函数,不得增行或删行,也不得更改程序的结构!试题程序:#include<stdlib.h>#include<conio.h>#include<stdio.h>#include<math.h>/*********found********/f(doublex)if(x==0.0||x==2.0)return0.0;elseif(xreturn(x-1)/ix-2);elsereturn(x+1)/(x-2);doublefun(intn)inti;doubles=0.0,y;for(i=-n;i<=n;i++)(y=f(1.0*i);s+y]/********found********/returnsvoidmain()(system("CLS");printf("%f/n",fun(5));
问答题填空题
请补充函数fun(),该函数的功能是:把字符串str中的字符按字符的ASCII码降序排列,处理后的字符串仍然保存在原串中,字符串及其长度作为函数参数传入。
例如,如果输入“cdefgh”,则输出为“hgfedc”。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun()的横线上填入所编写的若干表达式或语句。
试题程序:
#include
#define N 80
void fun(char s[],int n)
{
int i, j;
char ch;
for(i=0;i
问答题请编写函数fun,对长度为7个字符的字符串,除首、尾字符外,将其余5个字符按ASCII码降序排列。
例如,原来的字符串为:CEAedca,排序后输出为: CedcEAa。
注意:部分源程序在文件PROG1.C中。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。
#include
#include
#include
void fun (char *s,int num)
{
}
NONO()
{
/*请在此函数内打开文件,输入测试数据,调用fun函数,输出数据,关闭文件。 */
char s[10];
FILE *rf, *wf ;
int i = 0 ;
rf= fopen("in.dat","r");
wf — fopen ("out.dat","W");
while(i< 10) {
fgets (s,10,rf);
s[7] = 0 ;
fun (s,7);
fprintf (wf, "%s/rll" s);
i++ ;
)
fclose (rf);
fclose (wf);
}
main()
{
char s[10];
printf("输入7个字符的字符串:");
gets (s);
fun (s,7);
printf ("/n%s",s);
NONO();
}
问答题规定输入的字符串中只包含字母和*号。请编写函数fun,其功能是:除了字符串前导的*号之外,将串中其他水号全部删除。在编写函数时,不得使用C语言提供的字符串函数。例如,字符串中的内容为“****A*BC*DEF*G*******”,删除后,字符串中的内容应当是“****ABCDEFG”。注意:部分源程序给出如下。请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。试题程序:#include<string.h>#include<stdio.h>#include<conio.h>void fun(char*a){}main(){ char s[81]; printf("Enter astring:\n"); gets(S); fun(s); printf("The string after deleted:\n"); puts(s);}
问答题编写函数fun,其功能是:从字符串中删除指定的字符。同字母的大、小写按不同字符处理。
例如,若程序执行时输入字符串为:
“turbo c and borland c++”
从键盘上输入字符n,则输出为:
“turbo c ad borlad c++”
如果输入的字符在字符串中不存在,则字符串照原样输出。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。
试题程序:
#include<stdio.h>
#include<string.h>
void fun(char s[],int c)
{
}
main()
{
static char str[]="turbo c and borland c++";
char ch;
printf("原始字符串:%s/n",str);
printf("输入一个字符:");
scanf("%c",
fun(str,ch);
printf("str[]=%s/n",str);
strcpy (str,"turbo c and borland c++");
fun(str,"a");
}
问答题请编写一个函数void fun(char*ss),其功能是:将字符串 ss中所有下标为偶数位置上的字母转化为大写(若该位置上不是字母,则不转换)。
例如,若输入abc4Efg,则应输出AbC4EfG。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。
试题程序:
#include<conio. h>
#include<stdio. h>
void fun ( char *ss)
{
}
main ( )
{
char tt[51];
clrscr ();
printf("Please enter an character string
within 50 characters:/n");
gets (tt);
printf ("/n/nAfter changing, the string/n
%s", tt);
fun (tt);
printf("/nbecomes/n /%s",tt);
}
问答题请编写函数void fun(int x,int pp[],int*n),它的功能是:求出能整除x且不是偶数的各整数,并按从小到大的顺序放在pp所指的数组中,这些除数的个数通过形参n返回。
例如,若x中的值为30,则有4个数符合要求,它们是1、3、5、15。
注意:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。
试题程序:
#include<conio.h>
#include<stdio.h>
#include<stdlib.h>
void fun(int x,int pp[],int *n)
{
}
void main()
{
int x,aa[1000],n,i;
system("CLS");
printf("/nPlease enter an integer number:/n");
scanf("%d",&x);
fun(x,aa,&n);
for(i=0;i<n;i++)
printf("%d",aa[i]);
printf("/n");
}
问答题请编一个函数fun,函数的功能是使实型数保留2位小数,并对第三位进行四舍五入(规定实型数为正数)。
例如:实型数为1234.567,则函数返回1234.570000;
实型数为1234.564,则函数返回1234.560000。
注意:部分源程序存在文件PROG1.C中。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入编写的若干语句。
给定源程序如下。
#include<stdio.h>
float fun(float h)
{
}
main()
{ float a;
printf("Enter a:");scanf("%f",
printf("The original data is:");
printf("%f/n/n",a);
printf("The result:%f/n",fun(a));
}
问答题请编写函数fun,函数的功能是求出二维数组周边元素之和,作为函数值返回。二维数组中的值在主函数中赋予。 例如:二维数组中的值为: 1 3 5 7 9 2 9 9 9 4 6 9 9 9 8 1 3 5 7 0 则函数值为61。 注意:部分源程序存在文件PROG1.C文件中。 请勿改动主函数mare和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。l #include<stdio.h>2 #define M 43 #define N 54 int fun(int a[M][N])5 {67 }8 main()9 { Int aa[M][N]={{1,3,5,7,9},{2,9,9,9,4},{6,9,9,9,8},{1,3,5,7,0}};10 int i,j,y;void NONO();11 printf(''The original data is:\n'');12 for(i=0;i<M; i++)13 { for(j=0;j<N;j++)printf(''%6d'',aa[i][j]);14 printf(''\n'');15 }16 y=fun(aa);17 printf(''\nThe sum:%d\n'',y);18 printf(''\n'');19 NONO( );20 }21 void NONO( )22 {/*请在此函数内打开文件,输入测试数据,调用fun函数,输出数据,关闭文件。*/23 int i,j,y,k,aa[M][N];24 FILE *rf,*wf;25 rf=fopen(''in.dat'',''r'');26 wf=fopen(''out.dat'',''w'');27 for(k=0;k<10;k++){28 for(i=0;i<M;i++)29 for(j=0;j<N;j++)fscanf(rf,''%d'',32 }33 fclose(rf);34 fclose(wf);35 }
问答题下列给定程序中,函数fun的功能是:求出如下分数序列的前n项之和,和值通过函数值返回。例如,若n=5,则应输出8.391667。请改正程序中的错误,使其得出正确的结果。注意:不要改动main函数,不得增行或删行,也不得更改程序的结构!试题程序:#include<stcllib.h>#include<conio.h>#include<stdio.h>/*********found*********/voidfun(intn){inta=2,b=1,c,k;doubles=0.0;for(k=1;k<=n;k++){/*********found*********/s=s+(Double)a/b;c=a;a=a+b;b=c;}return(s);}voidmain(){intn=5;system("CLS");printf("/nThevalueoffunctionis:%1f/n",fun(n));}
问答题N名学生的成绩已在主函数中放入一个带有头结点的链表结构中,h指向链表的头结点。请编写函数fun,其功能是:找出学生的最高分,并由函数值返回。
注意
:部分源程序给出如下。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。
试题程序:
#include <stdio.h>
#include <stdlib.h>
#define N 8
struct slist
{
double s;
struct slist *next;
};
typedef struct slist 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)
/*产生8个结点的链表,各分数存入链表中*/
{
q=(STREC*)malloc(sizeof(STREC));
p->s=s[i];i++;p->next=q;
p=q;
}
p->next=NULL;
return h;/*返回链表的首地址*/
}
outlist(STREC*h)
{
STREC *p;
p=h;
printf("head");
do
{
printf("->%2.0f",p->s);
p=p->next;
}/*输出各分数*/
while(p->next!=NULL);
printf("/n/n");
}
void main()
{
double s[N]={85,76,69,85,91,72,64,87}, max;
STREC *h;
h=creat(s);
outlist(h);
max=fun(h);
printf("max=%6.1f/n ",max);
}
问答题
规定输入的字符串只包含字母和*号。请编写函数fun,它的功能是:将字符串中的前导*号全部删除,中间和尾部的*号不删除。
例如,字符串中的内容为:*******A*BC*DEF*G****,删除后,字符串中的内容应当是:A*BC*DEF*G****。在编写函数时,不得使用C语言提供的字符串函数。
注意:部分源程序在文件PROG1.C中。
请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入你编写的若干语句。
#include <stdio.h>
void fun(char *a)
{
}
main()
{ char s[81];
void NONO();
printf("Enter a 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);
}