C语言结构体初始化例子
#include <stdio.h> main() { struct student{ char no[8]; char name[8]; int score; }; struct student ab[10]={ { "2020001","张三1",156 },{ "2020002","张三2",157 },{ "2020003","张三3",158 },{ "2020004","张三4",159 },{ "2020005","张三5",160 },{ "2020006","张三6",161 },{ "2020007","张三7",134 },{ "2020008","张三8",126 },{ "2020009","张三9",186 },{ "2020010","张三10",156 } }; struct student stmax,stmin; int max,min,a; stmax=stmin=ab[0]; for(a=1;a<=9;a++) { if (ab[a].score>stmax.score) stmax=ab[a]; if (ab[a].score<stmin.score) stmin=ab[a]; } printf("最高分对应的姓名%s,学号为%s",stmax.name,stmax.no); printf("\n最低分对应的姓名%s,学号为%s",stmin.name,stmin.no); getchar(); }