38.有以下定义和语句:
struct workers
{int num;char name[20];char C;
struct
(int day;int month;int year;)S;
};
struct workers w,*pw;
pw=&w;
能给w中year成员赋1980的语句是( )。
A.*pw.year=1980;
B.w.year=1980;
C.pw->year=1980
D.w.S.year=1980;
39.有以下程序:
#include
main( )
{int a=2,b=2,C=2;
print{("%d\n",a/b&c);
}
程序运行后的输出结果是( )。
A.0
B.1
C.2
D.3
40.有以下程序:
#include
main( )
{FILE*fp;char str[10];
fp=fopen("myfile,dat","");
{puts("abe",ip);fclose(fp);
fp=fopen("myfile.dat","a*");
fprintf(fp,"%d",28);
rewind(fp);
fscanf(fp,"%S",str);puts(str);
fclose(fp);
}
程序运行后的输出结果是( )。
A.abc
B.28c
C.abc28
D.内类型不一致而出错
二、基本操作题
请补充main( )函数,该函数的功能是:如果数组arr的前一个元素比后一个元素小,则把它保存在数组bb中并输出。
例如,若数组中的元素为:“40,68,62,33,35,52,48,95,66,73”,则输出:“40,33,35,48,66”。
注意:部分源程序给出如下。
请勿改动函数( )main和其他函数中的任何内容,仅在main( )函数的横线上填入所编写的若干表达式或语句。
试题程序:
#include
#include
#define M l0
void main( )
{
int i,n=0;
int arr[M]=(40,68,62,33,35,52,48,95,66,73);
int bb[M];
system("CLS");
for(i=0;i<【1】;i++)
if(arr[i]【2】;
printf("\n***display bb***\n");
for(i=0;iprintf("bb[%d]=%2d",【3】);
}
三、程序改错题
给定程序中,函数proc( )的功能是:使数组中的元素的值缩小5倍。
请修改程序中的错误,使它能得出正确的结果。
注意:不要改动main( )函数,不得增行或删行,也不得更改程序的结构。
试题程序:
#include
#include
#include
float m[lO];
//****found****
int proc(void)
{
int j;
printf("In subfunc after calling\n");
for(j=0;j<10;j++)
{
//****found****
printf("%f",m[j]%5);
}
}
void main( )
{
int i;
printf("In main before calling\n");
for(i=0;i<10;i++)
{
m[i]=i+20;
printf("%f",m[i]);
}
proc( );
printf("\nln main after calling\n");
for(i=0;i<10;i++)
printf("%f",m[i]/5);
}
四、程序设计题
学生的记录由学号和成绩组成,M名学生的数据已在主函数中放入结构体数组stu中,请编写函数proc( ),其功能是:按分数的高低排列学生的记录,高分在前。
注意:部分源程序给出如下。
请勿改动main( )函数和其他函数中的任何内容,仅在函数proc( )的花括号中填入所编写的若干语句。
试题程序:
#include
#define M l6
typedef struct
{
char num[l0];
int S;
}
STREC:
void proc(STREC a[])
{
int i,j;
STREC t;
for(i=1;i排序*/
for(j=0;jif(a[j].s的记录,高分在前*/
{t=a[j];a[j]=a[j+1];a[j+1]=t;)
}
void main( )
{
STREC stu[M]={{"GA005",85),{"GA003",76},
{"GA002",69},{"GA004",85),{"GA001",91),
{"GA007",72),{"GA008",64),{"GA006",87),
{"GA015",85),{"GA013",91),{"GA012",64),
{¨GA014",91),{"GA011",66),{"GA017",64},
{"GA018",64),{"GA016",72}};
int i;
proc(stu);
printf("The data after sorted:\n");
for(i=0;i{
if(i%4= =0)
//每行输出4个学生记录
printf("n");
printf("%s%4d",stu[i],num,stu[i].s);
}
printf("\n");
}