.編一個(gè)程序,輸入10個(gè)職工的編號、姓名、基本工資、職務(wù)工資,求出其中“基本工資十職務(wù)工資”少的職工姓名并輸出。
「解」類似上一程序,直接給出程序如下:
# 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個(gè)人的編號、姓名、基本工資、職務(wù)工資 \n”, N);
for(p=person; 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 if (p -> basel+p -> base2< minp -> basel+ minp -> base2) minp =p;
printf(“基本工資與職務(wù)工資和少的職工是%s \n”,minp -> name);
printf(“他的基本工資與職務(wù)工資和是%.2f \n”,minp -> basel+ minp -> base2);
}
3.編一個(gè)程序,輸入10個(gè)學(xué)生的學(xué)號、姓名、3門課程的成績,求出總分高的學(xué)生姓名并輸出。
「解」類似上一程序,直接給出程序如下:
# 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個(gè)學(xué)生的編號、姓名、三門課程成績 \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(“高總分的學(xué)生是%s他的總分是 %d \n”, maxp -> name, maxs);
}
「解」類似上一程序,直接給出程序如下:
# 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個(gè)人的編號、姓名、基本工資、職務(wù)工資 \n”, N);
for(p=person; p
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
printf(“基本工資與職務(wù)工資和少的職工是%s \n”,minp -> name);
printf(“他的基本工資與職務(wù)工資和是%.2f \n”,minp -> basel+ minp -> base2);
}
3.編一個(gè)程序,輸入10個(gè)學(xué)生的學(xué)號、姓名、3門課程的成績,求出總分高的學(xué)生姓名并輸出。
「解」類似上一程序,直接給出程序如下:
# 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個(gè)學(xué)生的編號、姓名、三門課程成績 \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(“高總分的學(xué)生是%s他的總分是 %d \n”, maxp -> name, maxs);
}

