# 吵列题

9.1
#include<stdio.h>
int main()
{struct Student //声明结构体类型struct Student
{
long int num; //以下4行为结构体的成员
char name[20];
char sex;
return 0;
}

9.2
#include<stdio.h>
int main()
{struct Student //声明结构体类型struct Student
{
int num;
char name[20];
float score;
}student1,student2; //定义两个结构体变量 student1,student2
scanf("%d%s%f",&student1.num,student1.name,&student1.score); //输入学生1的数据
scanf("%d%s%f",&student2.num,student2.name,&student2.score); //输入学生2的数据
printf("The higher score is:\n");
if(student1.score>student2.score)
printf("%d %s %6.2f\n",student1.num,student1.name,student1.score);
else if(student1.score<student2.score)
printf("%d %s %6.2f\n",student2.num,student2.name,student2.score);
else
{
printf("%d %s %6.2f\n",student1.num,student1.name,student1.score);
printf("%d %s %6.2f\n",student2.num,student2.name,student2.score);
}
return 0;
}

9.3
#include<string.h>
#include<stdio.h>
struct Person //声明结构体类型struct Person
{
char name[20]; //候选人姓名
int count; //候选人得票数
int main()
{
int i,j;
for(i=1;i<=10;i++)
{
for(j=0;j<3;j++)
}
printf("\nResult:\n");
for(i=0;i<3;i++)
return 0;
}

9.4
#include<stdio.h>
struct Student //声明结构体类型 struct Student
{
int num;
char name[20];
float score;
};
int main()
{
struct Student stu[5]={{10101,"Zhang",78},{10103,"Wang",98.5},{10106,"Li",86},{10108,"Ling",73.5},{10110,"Sun",100}};//定义结构体数组并初始化
struct Student temp; //定义结构体变量temp,用作交换时的临时变量
const int n=5; //定义常变量 n
int i,j,k;
printf("The order is:\n");
for(i=0;i<n-1;i++)
{ k=i;
if(stu[j].score>stu[k].score)//进行成绩比较
k=j;
temp=stu[k];
stu[k]=stu[i];
stu[i]=temp;//stu[k]和stu[i]元素互换
}
for(i=0;i<n;i++)
printf("%6d %8s %6.2f\n",stu[i].num,stu[i].name,stu[i].score);
printf("\n");
return 0;
}

9.5
#include<stdio.h>
#include<stdlib.h>
struct Student//声明结构体类型 struct person
{
int num;
char name[20];
char sex;
int age;
};
struct Student stu[3]={{10101,"zhang",'M',78},{10103,"wang",'M',98},{10106,"li",'M',86}};//定义结构体数组并初始化
main()
{struct Student *p;//定义指向struct student类型数据的指针变量p
printf("NO.Name sex age\n");
for(p=stu;p<stu+3;p++)
printf("%d,%s,%c,%d",p->num,p->name,p->sex,p->age);
return 0;
}

9.6

#include<stdio.h>
struct Student
{
int num;
char name[20];
char sex;
int age;
}stu[3]={{10101,"lilin",'M',18},{10101,"zhang fang",'M',19},{10104,"wang min",'F',20}},*p;
int main()
{
printf("No. Name sex age\n");
for(p=stu;p<stu+3;p++)
printf("%5d %-20s %2c %4d\n",p->num,p->name,p->sex,p->age);
return 0;
}
9.7

#include<stdio.h>
#define N 3

struct Student
{
int num;
char name[20];
float score[3];
float aver;
};

int main()
{
void input(struct Student stu[]);
struct Student max (struct Student stu[]);
void print(struct Student stu);
struct Student stu[N],*p = stu;
input(p);
print(max(p));
return 0;
}

void input(struct Student stu[])
{
int i;
printf("请输入各学生的信息：学号、姓名、三门课成绩：\n");
for(i = 0;i < N;i ++)
{
scanf("%d %s %f %f %f",&stu[i].num,stu[i].name,&stu[i].score[0],
&stu[i].score[1],&stu[i].score[2]);
stu[i].aver = (stu[i].score[0]+stu[i].score[1]+stu[i].score[2])/3.0;
}
}

struct Student max(struct Student stu[])
{
int i;
int m = 0;;
for(i = 0; i < N;i ++)
{
if(stu[i].aver > stu[m].aver)
{
m = i;
}
}
return stu[m];
}

void print(struct Student stud)
{
printf("\n 成绩最高的学生:\n");
printf("学号:%d\n",stud.num);
printf("姓名:%s\n",stud.name);
printf("三门课成绩:%5.1f,%5.1f,%5.1f\n",stud.score[0],stud.score[1],stud.score[2]);
printf("平均成绩:%6.2f\n",stud.aver);
}

posted @ 2017-04-11 17:01  这都啥跟啥  阅读(114)  评论(0编辑  收藏  举报