c语言 指针 求极值

来源:百度知道 编辑:UC知道 时间:2024/06/04 17:06:08
struct stu {
char name[12];
int age;
double height;
} staff[3] ={
{“Ann”, 22, 164.0},
{“Candy”, 23, 152.7},
{“Nancy”, 28, 170.5}};
问题:检索身高最高的人 提示struct person *p, *pmax;

我写的
struct stu
{
char name[12];
int age;
double height;}boy[3] ={
{“Ann”, 22, 164.0},
{“Candy”, 23, 152.7},
{“Nancy”, 28, 170.5}};

};
main()
{
struct stu *ps;
void ave(struct stu *ps);
ps=boy;
ave(ps);
}
void ave(struct stu *ps)
{
int i,temp;
temp=ps->;
for(if(temp>ps->height)
temp=ps->height;

printf("highest=%f\n",temp);
}
应该怎么改一下?
谢谢啦

你写的哪个有很多错误,是不是贴错了

#include "stdio.h"
struct stu
{
char name[12];
int age;
double height;}boy[3] ={
{"Ann", 22, 164.0},
{"Candy", 23, 152.7},
{"Nancy", 28, 170.5}};

main()
{

void ave(struct stu *ps);
ave(boy);
getch();
}
void ave(struct stu *ps)
{struct stu *pmax;
int i;
for(i=0;i<2;i++)
if( (ps+i)->height > (ps+i+1)->height )
pmax=ps;
else
pmax=ps+i+1;
printf("The heighest one is \"%s\".\n",pmax->name);
}

答案都给你了,你还来,是不是还想给我20分啊,我现在在凑分想请别人一起做个大程序,所以,那么,好兄弟,大概这20分你也给了我吧,我感激不尽,他日定有回报。

#include<stdio.h>
struct person {
char name[12];
int age;
double height;
} staff[3] ={ {"Ann", 22, 164.0},
{"Candy", 23, 152.7},
{"Nancy", 28, 170.5}};
void main()