#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 { 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函数
学生的记录由学号和成绩组成,N名学生的数据已在主函数中放入结构体数组s中,请编写函数fun,它的功能是:表格做的好
修改后如下:
#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
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);
}
#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
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);
}
#include
#include
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
请按任意键继续. . .