数据结构D1作业

#include<stdio.h>

#include<string.h>

typedef struct stu

{

char name[20];

double height;

int score;

}stu,*stu_p;

int main(int argc, const char *argv[])

{

int i=0;

int j=0;

char temp_name[20]="";

int temp_score=0;

double temp_height=0;

stu arr[7]={};

stu_p p=arr;

for(i=0;i<7;i++)

{

printf("请输入学生姓名>>");

scanf("%s",(p+i)->name);

printf("请输入学生身高>>");

scanf("%lf",&((p+i)->height));

printf("请输入学生成绩>>");

scanf("%d",&((arr+i)->score));

}

for(i=0;i<6;i++)

{

for(j=0;j<6-i;j++)

{

if((*(p+j)).score>(*(p+j+1)).score)

{

temp_score=(*(p+j)).score;

(*(p+j)).score=(*(p+j+1)).score;

(*(p+j+1)).score=temp_score;

temp_height=(*(p+j)).height;

(*(p+j)).height=(*(p+j+1)).height;

(*(p+j+1)).height=temp_height;

strcpy(temp_name,(p+j)->name);

strcpy((p+j)->name,(p+j+1)->name);

strcpy((p+j+1)->name,temp_name);

}

}

}

for(i=0;i<7;i++)

{

printf("%d\t",(*(p+i)).score);

}

printf("\n");

return 0;

}

相关推荐
青岛少儿编程-王老师6 小时前
CCF编程能力等级认证GESP—C++7级—20250927
数据结构·c++·算法
nanaki502138 小时前
数据结构(3) ----------- 栈、队列
数据结构
一只小透明啊啊啊啊8 小时前
b树,b+树,红黑树
数据结构·b树·b+树
Mingze03148 小时前
C语言四大排序算法实战
c语言·数据结构·学习·算法·排序算法
程序员东岸9 小时前
学完顺序表后,用 C 语言写了一个通讯录
数据结构·笔记·学习
独自破碎E10 小时前
Leetcode2166-设计位集
java·数据结构·算法
Cikiss10 小时前
LeetCode160.相交链表【最通俗易懂版双指针】
java·数据结构·算法·链表
2301_7890156212 小时前
算法与数据结构——排序算法大全
c语言·开发语言·数据结构·c++·算法·排序算法·visual studio
无限进步_12 小时前
冒泡排序的多种实现方式详解
c语言·数据结构·c++·算法
new coder13 小时前
[算法练习]Day 7: 变长滑动窗口
数据结构·算法·leetcode