二維陣列按某列排序交換元素
阿新 • • 發佈:2021-02-03
二維陣列按某列排序需要交換各個列的元素;此時利用結構體陣列比較方便,結構體陣列可以直接交換,裡面的各個成員就i能交換了。
#include "stdio.h" #include "stdlib.h" void main() { struct student { int age; float score; }; struct student a, b; a.age = 10; a.score = 100; b.age = 11; b.score = 99; struct student c; c = a; a = b; b = c; printf("a:%d %f\n", a.age, a.score); printf("b:%d %f\n", b.age, b.score); system("pause"); }