学生的记录由学号和成绩组成,N名学生的数据已在主函数中放入结构体数组s中,请编写函数fun,它的功能是:

指定分数范围内的学生数据放在b所指的数组中,分数范围内的学生人数由函数值返回,在主函数中输出结果。
例如,输入的分数是60和69,则应当把分数在60到69的学生数据进行输出,包含60分和69分的学生数据。主函数中将把60放在low中,把69放在heign中。
# include "stdio.h"
# define N 10
struct student
{
int num;
int score;
}
int fun(struct student s[],struct student b[])
{
int heigh,low,count=0;
printf("输入上下限\n");
scanf("%d,%d",&heigh,&low);
for(i=0;i<N;i++)
{
if(low<=s[i].score<=heigh)
{
b[count].num=s[i].num;
b[count].score=s[i].score;
count++;
}
}
return count;
}
void main()
{
struct student s[N],b[];
int t;
s[].num={1,2,3,4,5,6,7,8,9,10};
s[].score={60,62,64,66,68,70,75,80,85,90};
t=fun(s,b);
if(t==0)
printf("范围内没有人\n");
else
printf("范围内人数为:%d\n",t);
}
我自己编的,可是错了,求大神帮我改一改,谢谢了

#include "stdio.h"

#define N 10

struct student

{

int num;

int score;

};

int fun(struct student s[],struct student b[])

{

int heigh,low,count=0;

printf("输入上下限\n");

scanf("%d%d",&heigh,&low);

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

{

baiif( (low <= s[i].score) && (s[i].score <= heigh) )

{

b[count].num=s[i].num;

b[count].score=s[i].score;

count++;

}

}

return count;

}

void main()

{

student b[N];

int t;

student s[N]={1,60,2,62,3,64,4,66,5,68,6,70,7,75,8,80,9,85,10,90};

t=fun(s,b);

if(t==0)

printf("范围内没有人\n");

else

printf("范围内人数为:%d\n",t);

}

扩展资料:

C/C++ 语言标准库中没有fun函数。fun函数是自定义函数,是使用来举例或作语法演示的,需要在使用前自行定义声明。

fun一词没什么特别含义,也可以换成别的名称,如"abc"或者"baidubaike"。它只表示引用之前出现的函数,以调用它执行一些需求,int fun(int x,int y)只是一个举例的函数名而已,以及其声明的参数类型。

参考资料来源:百度百科-fun函数

温馨提示:答案为网友推荐,仅供参考
第1个回答  2019-12-21
学生的记录由学号和成绩组成,N名学生的数据已在主函数中放入结构体数组s中,请编写函数fun,它的功能是:表格做的好
第2个回答  推荐于2017-11-25
修改后如下:
#include "stdio.h"
#define N 10
struct student
{
int num;
int score;
};

int fun(struct student s[],struct student b[])
{
int heigh,low,count=0;
printf("输入上下限\n");
scanf("%d%d",&heigh,&low);
for(int i=0;i<N;i++)
{
if( (low <= s[i].score) && (s[i].score <= heigh) )
{
b[count].num=s[i].num;
b[count].score=s[i].score;
count++;
}
}
return count;
}
void main()
{
student b[N];
int t;
student s[N]={1,60,2,62,3,64,4,66,5,68,6,70,7,75,8,80,9,85,10,90};
t=fun(s,b);
if(t==0)
printf("范围内没有人\n");
else
printf("范围内人数为:%d\n",t);
}本回答被提问者采纳
第3个回答  2012-06-04
#include "stdio.h"
#define N 10
struct student
{
int num;
int score;
};

int fun(struct student s[],struct student b[])
{
int i,heigh,low,count=0;
printf("输入上下限\n");
scanf("%d%d",&low,&heigh);
for(i=0;i<N;i++)
{
if( (low <= s[i].score) && (s[i].score <= heigh) )
{
b[count].num=s[i].num;
b[count].score=s[i].score;
count++;
}
}
return count;
}
void main()
{
struct student b[N];
int t;
struct student s[N]={1,60,2,62,3,64,4,66,5,68,6,70,7,75,8,80,9,85,10,90};
t=fun(s,b);
if(t==0)
printf("范围内没有人\n");
else
printf("范围内人数为:%d\n",t);
}
第4个回答  2012-06-01
#include<stdio.h>
#include<string.h>

typedef struct student
{char num[10];
double score;
} strec ;
int fun(student*, int, student**,int,int);
int main()
{
strec s[5]={{"0001",90} ,{"0002",80.0},{"0003",70},{"0004",60},{"0005",50}};
strec *b;
int count = fun(s,5, &b, 60, 90);
for(int i = 0; i < count; i ++)
{
printf("%s %.2f\n", b[i].num, b[i].score);
}
}
int fun(strec* a,int num, strec **b,int l,int h)//l,h表示分数范围,第二个int表示传入a数组的元素个数
{
int count = 0;
strec * re = new strec[num];
for(int i = 0; i < num; i ++)
{
if(a[i].score >= l && a[i].score <= h)
{
count++;
re[i].score = a[i].score;
strcpy(re[i].num, a[i].num);
}
}
*b = re;
return count;
}

对你的函数修改了一下
int fun(student*, int, student**,int,int); //添加了一个int,第三个参数改为传入b的地址。
在vs 2008测试运行过了,结果如下:
0001 90.00
0002 80.00
0003 70.00
0004 60.00
请按任意键继续. . .