2.编一个程序,输入10个职工的编号、姓名、基本工资、职务工资,求出其中“基本工资十职务工资”最少的职工姓名并输出。
「解」类似上一程序,直接给出程序如下:
# include
# define N 10
struct person {
char no[10];
char name[20];
float base1;
float base2;
} person[N], *p, *minp;
void main ()
{ float d;
char buf[120];
printf(“输入%d个人的编号、姓名、基本工资、职务工资 n”, N);
for(p=person; p<PERSON+N; P++) {
scanf(“%s”, buf); strncpy(p - no,buf,9);
scanf(“%s”, buf); strncpy( p - name, buf, 19);
scanf(“%f”, &d);p - base1 =d;
scanf(“%f”,&d);p - base2=d;
}
for(minp=p=person; p<PERSON+N; P++)
if (p - basel+p - base2< minp - basel+ minp - base2) minp =p;
printf(“基本工资与职务工资和最少的职工是%s n”,minp - name);
printf(“他的基本工资与职务工资和是%.2f n”,minp - basel+ minp - base2);
}
3.编一个程序,输入10个学生的学号、姓名、3门课程的成绩,求出总分最高的学生姓名并输出。
「解」类似上一程序,直接给出程序如下:
# include
# include
# define N 10
struct stu {
char no[10];
char name[20];
int score[3];
} students[N],*p, *maxp;
void main()
{ char buf[120]; int maxs;
printf(“输入%d个学生的编号、姓名、三门课程成绩 n”, N);
for(p= students;p< students+N;p++) {
scanf(“%s”, buf); strncpy(p - no, buf, 9);
scanf(“%s”, buf); strncpy( p - name, buf,19);
scanf(“%d%d%d”,&p - score[O], &p - score[1], &p - score[2]);
}
for(maxp= p =students, maxs=-1; p< students+N; p++)
if( p - score[0] + p - score[1]+p - score[2] maxs) {
maxp=p;maxs=p -score[0]+p - score[1]+p -score[2];
}
printf(“最高总分的学生是%s他的总分是 %d n”, maxp - name, maxs);
}