二维数组按某列排序交换元素
二维数组按某列排序需要交换各个列的元素;此时利用结构体数组比较方便,结构体数组可以直接交换,里面的各个成员就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");
}

时光如水,总是无言。若你安好,便是晴天。
本文来自博客园,作者:OceanWaves,转载请注明原文链接:https://www.cnblogs.com/OceanWaves/p/12006985.html

浙公网安备 33010602011771号