指定分数范围内的学生数据放在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函数