- 11
- 0
- 约2.23千字
- 约 5页
- 2018-06-26 发布于河南
- 举报
二级c语言第七套上机练习
1 给定程序中,函数fun的功能是:将形参指针所指结构体数组中的3个元素,按num成员进行升序排序。
#include stdio.h
typedef struct
{ int num;
char name[10];
}PERSON;
/**********found**********/
void fun(PERSON ___std[]___)
{
/**********found**********/
___PERSON_ temp;
if(std[0].numstd[1].num)
{ temp=std[0]; std[0]=std[1]; std[1]=temp; }
if(std[0].numstd[2].num)
{ temp=std[0]; std[0]=std[2]; std[2]=temp; }
if(std[1].numstd[2].num)
{ temp=std[1]; std[1]=std[2]; std[2]=temp; }
}
main()
{ PERSON std[ ]={ 5,Zhanghu,2,WangLi,6,LinMin };
int i;
/**********found**********/
fun(___std___);
printf(\nThe result is :\n);
for(i=0; i3; i++)
printf(%d,%s\n,std[i].num,std[i].name);
}
2 给定程序中,函数fun的功能是:通过某种方式实现两个变量值的交换,规定不允许增加语句和表达式,例如:变量a中的值为3,b中的值为8,程序运行后,a中的值为8,b中的值为3。
#include conio.h
#include stdio.h
#include windows.h
int fun(int *x,int y)
{
int t;
/************found************/
t=*x;*x=y; /*原来是t=x; x=y*/
/************found************/
return(t); /*原来是return (y)*/
}
main()
{
int a=3,b=8;
system(cls);
printf(%d %d\n,a,b);
b=fun(a,b);
printf(%d %d\n,a,b);
}
3 学生的记录由学号和成绩组成,N名学生的数据已在主函数中放入结构体数组s中 ,请编写函数fun它的功能是:把高于等于平均分的学生数据放在h所指的数组中,高于等于平均分的学生数据放在h所指的数组中,高于等于平均分的学生人数通过形参放在传回,平均分通过函数值传回
#include stdio.h
#define N 12
typedef struct
{ char num[10];
double s;
} STREC;
double fun(STREC *a,STREC *b,int *n)
{ int i, j ; double aver=0;
*n=0;
for(i=0 ; iN; i++)
aver=aver+a[i].s; /*求和*/
aver=aver/N; /*计算平均分*/
for(i=0;iN; i++)
if(a[i].s=aver)
{ b[*n].s=a[i].s; /*将高于等于平均分的学生放在另一个数组b中*/
for(j=0 ; j10; j++)
b[*n].num[j]=a[i].num[j];
*n=*n+1;/*统计高于等于平均分的学生人数*/
}
return (aver) /*返回平均分*/
}
main()
{ STREC s[N]={{GA05,85},{GA03,76},{GA02,69},{GA04,85},{GA01,91},{GA07,72},{GA08,64},{GA06,87},{GA09,60},{GA11,79},{GA12,73},{GA10,90}};
STREC h[N];FILE *out;
int i,n;double ave;
ave=fun(s,h,n);
printf(The %d student data which is higher than %7.3f:\n,n,ave);
for(i=0;in;i++)
printf(%s %4.1f\n,h[i].num,h[i].s);
p
您可能关注的文档
最近下载
- 老师独家编写中考核心词版词day16音标.pdf VIP
- 2025至2030中国封装系统(SiP)芯片行业细分市场及应用领域与趋势展望研究报告.docx VIP
- 空调翅片管换热器设计计算.xls VIP
- 老师独家编写中考核心词版词day17音标.pdf VIP
- 星期一发的第十套中考题.docx VIP
- 瓷砖切割与铺贴工艺流程.pptx VIP
- 老师独家编写中考核心词版词day30音标.pdf VIP
- 佳能 奥西 VP 95 105 110 120 135 数码印刷系统中文维修手册 .pdf VIP
- 卫生技术人员专业技术资格考试.docx VIP
- 2021教师资格证面试小学语文教师招聘、考编、面试无生试讲万能模板(适用于部编版小学语文教材).pdf VIP
原创力文档

文档评论(0)