第1个回答 2014-05-28
#include <stdio.h>
int main (void)
{
int i, index, j, n;
struct address_list{
char name[20];
long birthday;
char phone[20];
}temp, friends[10];
scanf("%d", &n);
for(i = 0; i < n; i++)
scanf("%s%ld%s", friends[i].name, &friends[i].birthday, friends[i].phone);
for(i=0;i<n;i++)
{
index=i;
for(j=i+1;j<n;j++)
if(friends[j].birthday<friends[index].birthday)
index=j;
temp=friends[index];
friends[index]=friends[i];
friends[i]=temp;
}
for(i = 0; i < n; i++)
printf("%s %ld %s\n", friends[i].name, friends[i].birthday, friends[i].phone);
}
第2个回答 2014-05-28
#include<stdio.h>
struct book
{
char name[20];
float price;
};
void main()
{
struct book num[20];
int n,i,max,min,max_i,min_i;
printf("Input n:");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("Input the name,price of the %d book:",i+1);
memset(num[i].name,0,20);
scanf("%s %lf",num[i].name,num[i].price);
}
max=num[0].price;
max_i=0;
min=num[0].price;
min_i=0;
for(i=1;i<n;i++)
{
if(num[i].price>max)
max_i=i;
if(num[i].price<min)
min_i=i;
}
printf("The book with the max price:%s,price is:%.1f\n",num[max_i].name,num[max_i].price);
printf("The book with the min price:%s,price is:%.1f\n",num[min_i].name,num[min_i].price);
}本回答被网友采纳