char name[5][10],*highname,*lowname;
int rate[5],i,high,low;
printf("Enter name and points:\n");
for(i=0;i<5;i++)
scanf("%s %d",name[i],&rate[i]);
low=30000;high=0;
for(i=0;i<5;i++)
{
if(rate[i]>high)
{high=rate[i];
highname=name[i];}
if(rate[i]<low)
{low=rate[i];
lowname=name[i];}
}
printf("High point is %d by %s, and low point is %d by %s.",high,highname,low,lowname);
return 0;
}
我後來自己的寫法,還可以依序排出所有的高低:
#include <stdio.h>
int main(void){
char name[6][5],test[10];
int rate[6],temp;
int i,j;
for(i=0;i<6;i++)
{
printf("Enter name and rate:\n");
scanf("%s %d",name[i],&rate[i]);
}