1.思维导图
![在这里插入图片描述](https://img-blog.csdnimg.cn/d84733722c0f4756912ae2a1cfeaf2c0.png#pic_center)
2.定义结构体数组存储5个学生的信息:姓名,年龄,性别
![在这里插入图片描述](https://img-blog.csdnimg.cn/46b8b802b3764e40b1d81d41d3966c70.png)
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
struct STUDENT
{
int age;
char name[20];
char sex[20];
};
void input(struct STUDENT *p,int length);
void bubble(struct STUDENT *p,int length);
void output(struct STUDENT *p,int length);
int main()
{
struct STUDENT arr[3];
int length = sizeof(arr)/sizeof(arr[0]);
input(arr,length);
bubble(arr,length);
output(arr,length);
return 0;
}
void input(struct STUDENT *p,int length)
{
for(int i=0;i<length;i++)
{
scanf("%d",&p[i].age);
scanf("%s",p[i].name);
scanf("%s",p[i].sex);
}
}
void bubble(struct STUDENT *p,int length)
{
for(int i=1;i<length;i++)
{
for(int j=0;j<length-i;j++)
{
if(p[j].age>p[j+1].age)
{
struct STUDENT temp = p[j];
p[j]=p[j+1];
p[j+1]=temp;
}
}
}
}
void output(struct STUDENT *p,int length)
{
for(int i =0;i<length;i++)
{
printf("%d\n",p[i].age);
}
}
3.定义车辆a和车辆b,实现交换
![在这里插入图片描述](https://img-blog.csdnimg.cn/ffdb5a38d8f0495d8f549fe349db8aff.png)
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
struct CAR
{
char sign[20];
char color[20];
int price;
};
int main()
{
struct CAR a = {"大G","black",1000000};
struct CAR b = {"benz","white",10};
struct CAR temp = a;
a=b;
b=temp;
printf("%s,%s,%d\n",a.sign,a.color,a.price);
printf("%s,%s,%d\n",b.sign,b.color,b.price);
return 0;
}