zoukankan      html  css  js  c++  java
  • C语言程序设计 第七章 指针与结构体 指针数组 例题

    /* ---------------------------------------
       例7.19
       输入N个学生学号,姓名,成绩,并按成绩降序排列,并输出
       p指向结构体变量s1 , 则  s1.成员名,(*p).成员名,p->成员名 等价。
       本题采用自定义函数较为合适
      Author: emanlee  https://www.cnblogs.com/emanlee/
      Date: 2008-05-12
      --------------------------------------- */
    #include "stdio.h"
    #include "conio.h"
    #include "math.h"
    #include <string.h>
    #define N 2

    struct student
    {
       int num;
       char name[12];
       int score;
    };


    main( )
    {
       struct student s[N];
       struct student *p,*q[N];
       int i,j,k;
       printf (" Input %d student's num  name  score\n",N);
       p=s;
       for (i=0;i<N;i++) /* 输入 */
       {
           scanf("%d%s%d",&p->num,p->name,&p->score);
           q[i]=p++;
       }
       for (i=0;i<N-1;i++)   /*选择排序*/
       {
           k=i;
           for (j=i+1;j<N;j++)
              if (q[k]->score<q[j]->score)
                 k=j;
           if (k!=i)
           {
              p=q[i];
              q[i]=q[k];
              q[k]=p;
           }
       }
       printf("Number  Name       Score\n");    /*输出 */
       for (i=0; i<N; i++)
          printf("%-8d%-12s%-d\n",q[i]->num,q[i]->name,q[i]->score);
       getchar();     getchar();
    }
     /* --------------------------------------*/


  • 相关阅读:
    JS 原型模式 工厂模式 构造函数的区别
    JS 深入1
    理解DOM的一个例子
    Fuzzing参数
    神经网络相关知识和概念整理
    [转载] 系统、模型和仿真
    frp内网穿透,从外网访问内网资源
    常用软件配置
    141. 环形链表
    501. 二叉搜索树中的众数
  • 原文地址:https://www.cnblogs.com/emanlee/p/1192973.html
Copyright © 2011-2022 走看看