问答题

学生的记录由学号和成绩组成,M名学生的数据已在主函数中放人结构体数组stu中,请编写函数proc(),它的功能是:把指定分数范围之外的学生数据放在b所指的数组中,分数范围之外的学生人数由函数值返回。
例如,输入的分数是70和79,则应当把分数低于70和高于79的学生数据输出,不包含70分和79分的学生数据。主函数中把70放在low中,把79放在heigh中。
注意:部分源程序给出如下。
请勿改动main()函数和其他函数中的任何内容,仅在函数proc()的花括号中填人所编写的若干语句。
试题程序:
#include<stdio.h>
#define M 16
typedef struct
{
char num[10];
int s:
}
STREC;
int proc(STREC*a,STREC*b,int 1,int h)
{ }
void main()
{
STREC stu[M]={{"GA005",55),{"GA003",96},
{"GA002",80),{"GA004",68),
{"GA001",88},{"GA007",74},
{"GA008",85),{"GA006",89},
{"GA015",90),{"GA013”,53),
{"GA012",66},{"GA014”,82),
{"GA011",73},{"GA017",69),
{"GA018",64),{"GA016",86}};
STREC h[M];
int i,n,low,heigh,t;
printf("Enter 2 integer number low&
heigh:");
scanf("%d%d",&low,&heigh);
if(heigh<low) ’
{
t=heigh:
heigh=low;
low=t;
}
n=proc(stu,h,low,heigh);
printf("The student’S data out
%d--%d:\n",low,heigh);
for(i=0;i<n;i++)
printf("%S%4d\n",h[i].num,h[i].s);
//输出指定分数范围内的学生记录
printf("\n");
}

【参考答案】

int proc(STREC*a,STREC*b,int l,int h) {

int i,j=0;

for(i=0;i<M;i++)

if((a[i].s>=0&&a[i].s<1)||(a[i].s>h&&a

[i].s<=l00)) //通过if语句,来判断指定范围

之外的数

b[j++]=a[i];//放到b数组中

return j; //最后把其个数返回到主函数中 } 【解析】题目要求把指定范围之外的数放到b 中,将每一个学生的成绩与指定的成绩相比较,将符合条件的学生成绩放在数组b中,并将符合要求的学生个数返回给主函数。

(↓↓↓ 点击下方‘点击查看答案’看答案解析 ↓↓↓)

相关考题

问答题 请编一个函数void proc(int ttEM][N],int pp[N]),tt 指向一个M行N列的二维数组,求出二维数组每行中最大元素,并依次放入pp所指的一维数组中。二维数组中的数已在主函数中给出。 注意:部分源程序给出如下。 请勿改动main()函数和其他函数中的任何内容,仅在函数proc()的花括号中填入所编写的若干语句。 试题程序: #include<stdio.h> #include<conio.h> #include<stdlib.h> #define M 3 #define N 4 void proc(int ttrM3rN]。int pp[N]) {} void main() { int str[M][N]={ {34,56,84,78}, {23,84,93,12), {28,38,39,93}}; int p[N],i,j,k; system("CLS"); printf("The riginal data is:\n"); for(i=0;i<M;i++) { for(j=0;j<N;j++) printf("%6d",str[i][j]); printf("\n"); } proc(str,p); printf("\nThe result is:\n");for(k=0:k<M;k++) printf("%4d",p[k]); printf("n");}

问答题 请编写一个函数proc(),它的功能是:求出1~m(含m) 能被7或11整除的所有整数放在数组a中,通过n返回这些数的个数。 例如,若传给m的值为70,则程序输出: 7 11 14 21 22 28 33 35 42 44 49 55 56 63 66 70 注意:部分源程序给出如下。 请勿改动main()函数和其他函数中的任何内容,仅在函数proc()的花括号中填人所编写的若干语句。 试题程序: #include<stdlib.h> #include<conio.h> #include<stdio.h> #define N 100 void proc(int m,int*a,int*n) {} void main() { int arr[N],n,k; system("CLS"); proc(70,arr,&n); for(k=0;k<n;k++) if((k+1)%20==0)//每行输出20个数 { printf("%4d",arr[k]); printf("\n"); } else printf("%4d",arr[k]); printf("\n"); }

判断题 动火作业可以不办理动火许可证。( )