C语言编程笔试题(第十六套)

匿名网友 匿名网友 发布于: 2015-08-30 00:00:00
阅读 108 收藏 0 点赞 0 评论 0

编程题:

50.已知学生的记录由学号和学习成绩构成,N名学生的数据已存入a结构体数组中。请编写函数fun,该函数的功能是:找出成绩最高的学生记录,通过形参返回主函数(规定只有一个最高分)。已给出函数的首部,请完成该函数。

注意:部分源程序给出如下。

请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。

#include <stdio.h>

#include <string.h>

#include <conio.h>

#define  N  10

 

typedef  struct  ss

{

char  num[10];

int  s;

} STU;

void  fun(STU a[], STU *s)

{

 

}

main ( )

{

STU a[N]={ {“A01”,81},{“A02”,89},{“A03”,66},{“A04”,87},{“A05”,77},

{“A06”,90},{“A07”,79},{“A08”,61},{“A09”,80},{“A10”,71} }, m  ;

int  i;

clrscr();

printf(“***** The original data *****n”);

for ( i=0; i<N; i++ )

printf(“N0=%s  Mark=%dn”, a[i].num,a[i].s);

fun ( a, &m);

printf(“***** THE RESULT*****n”);

printf(“The top  :  %s , %dn”, m.num, m.s);

}

 

54.学生的记录由学号和成绩组成,N名学生的数据已在主函数中放入结构体数组s中,请编写函数fun,它的功能是;把低于平均分的学生数据放在b所指的数组中,低于平均分的学生人数通过形参n传回,平均分通过函数值返回。

注意:部分源程序给出如下。

请勿改动主函数main和其他函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。

#include  <stdio.h>

#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, &n );

printf (“The %d student data which is lower than %7.3f:n”, n, ave );

for (i=0; i<n; i++)

printf (“%s %4.1fn”, h[i]. num, h[i]. s);

printf (“n”);

out=fopen (“out13.dat”,”w”);

fprintf (out,  “%dn%7.3fn”,  n,  ave);

for (i=0; i<n; i++)

for(j=i+1;j<n;j++)

if(h[i].s>h[j].s)

{

t=h[i] ;

h[i]=h[j];

h[j]=t;

}

for(i=0;i<n; i++)

fprintf (out, “%4.1fn”, h[i].s );

fclose (out );

}

 

改错题:

16.下列给定程序中的函数Creatlink的功能是:创建带头结点的单向链表,并为各结点数据域赋0到m-1的值。

请改正函数Creatlink中的错误,使它能得出正确的结果。

注意:不要改动main函数,不得增行或删行,也不得更改程序的结构!

试题程序:

#include <stdio.h>

#include <conio.h>

#include <stdlib.h>

typedef struct aa

{

int data;

struct aa *next;

} NODE;

NODE *Creatlink(int n, int m)

{

NODE *h=NULL, *p, *s;

int i;

s=(NODE *)malloc(sizeof(NODE));

h=p;

/********found********/

p->next=NULL;

for(i=1;i<n;i++)

{

s=(NODE *)malloc(sizeof(NODE));

/********found********/

s->data=rand()%m;

s->next=p->next;

p->next=s;

p=p->next;

}

/********found********/

return p;

}

outlink(NODE *h)

{

NODE *p;

p=h->next;

printf(“nnTHE LIST :nn HEAD”);

while(p)

{

printf(“->%d “,p->data);

p=p->next;

}

printf(“n”);

}

main()

{

NODE *head;

clrscr();

head=Creatlink(8,22);

outlink(head);

}

 

 

18.下列给定程序中,函数fun的功能是:实现两个整数的交换。例如给a和b分别输

入60和65,输出为:a=65 b=60。

请改正程序中的错误,使它能得出正确的结果。

注意:不要改动main函数,不得增行或删行,也不得更改程序的结构!

试题程序:

#include <stdio.h>

#include <conio.h>

/********found********/

void fun(int a,int b)

{

int t;

/********found********/

t=b;

b=a;

a=t;

}

 

main()

{

int a,b;

clrscr();

printf(“Enter a,b: “);

scanf(“%d%d”,&a,&b);

fun(&a,&b);

printf(“a=%d b=%dn”,a,b);

}

评论列表
文章目录