帮我啊,谢谢了(10)

来源:百度知道 编辑:UC知道 时间:2024/05/26 04:32:33
2.程序填空
(1)下列函数findbook的功能为:在有n个元素的数组s中查找书名为a的书,若找到,函数返回数组下标,否则,函数返回-1,请填写适当的符号或语句,使程序实现其功能,程序以文件名sy8_4.c存盘。
#include<stdio.h>
struct bdata
{ int id;
char bname[20];
float price;
}
int findbook(struct bdata st[],int n,char s[])
{ int i;
for(i=0;i<n;i++)
if(________) return i;
__________________;
}
void main()
{ struct bdata book[100];
char st[20];
int index;
printf("请输入要查找书名:";
gets(st);
index=findbook(_______________);
... ...
}
(2)下列函数average功能为:计算5名学生3门课成绩的平均分,请填写适当的符号或语句,使程序实现其功能,程序以文件名sy8_5.c存盘。
#include<stdio.h>
#define m 3
#define n 5
struct stud
{ int no;
char name[16];
float mark[m];
float ave;
};
void average(struct stud st[])
{int i,j;
float sum;
for(i=0;i<n;i++)
{sum= ;
for(j=0;j<m;j++)
sum=

#include<stdio.h>
struct bdata
{ int id;
char bname[20];
float price;
}
int findbook(struct bdata st[],int n,char s[])
{ int i;
for(i=0;i<n;i++)
if(strcmp(st[i].bname, s) == 0) return i;
return -1;
}
void main()
{ struct bdata book[100];
char st[20];
int index;
printf("请输入要查找书名:";
gets(st);
index=findbook(book, 100, st);
... ...
}