zoukankan      html  css  js  c++  java
  • C语言结构体(摘抄C语言设计)

    struct  Student  stu_1;//定义struct  Student 类型的变量stu_1
    struct  Student  *p;//定义指向struct Student类型数据的指针变量
    p=&stu_1;//p指向stu
    如果p指向一个结构体变量stu等价:

    (1)stu.成员名(如stu.num)

      (2)  (*p).成员名(如(*p).num)

      (3)p->成员名(如p->num)

     1 //输出最高成绩
     2 
     3 #include<stdio.h>
     4 #define N 3
     5 struct Student
     6 {
     7     int num;
     8     char name[20];
     9     float score[3];
    10     float aver;
    11 };
    12 void input(struct Student stu[]);
    13 struct Student max(struct Student stu[]);
    14 void print(struct Student stu);
    15 int  main()
    16 {
    17     struct Student stu[N],*p=stu;
    18     input(p);
    19     print(max(p));
    20     return 0;
    21 }
    22 void input(struct Student stu[])
    23 {
    24     int i;
    25     printf("请输入各学生的信息:学号,姓名,三门课成绩:
    ");
    26     for(i=0;i<N;i++)
    27     {
    28        scanf("%d %s %f %f %f",&stu[i].num,stu[i].name,&stu[i].score[0],&stu[i].score[1],&stu[i].score[2]);
    29        stu[i].aver=(stu[i].score[0]+stu[i].score[1]+stu[i].score[2])/3.0;//求平均值
    30     }
    31 }
    32 struct Student max(struct Student stu[])
    33 {
    34     int i,m=0;
    35     for(i=0;i<N;i++)
    36     {
    37      if(stu[i].aver>stu[m].aver) m=i;
    38     }
    39     return stu[m];
    40 }
    41 void print(struct Student stud)
    42 {
    43   printf("
    成绩最高的是
    ");
    44   printf("%d",stud.num);
    45 
    46 }
    View Code

  • 相关阅读:
    【leetcode】1. Two Sum
    【leetcode】32. Longest Valid Parentheses
    【leetcode】20. Valid Parentheses
    scala细节
    【转】CentOS下firefox安装flash说明
    Spring 容器(一)
    源码学习快捷键
    Gradle编译spring3.x报错找不到itextpdf4.2.2解决方案
    Insertion Sort
    Bubble Sort
  • 原文地址:https://www.cnblogs.com/wy9264/p/11415693.html
Copyright © 2011-2022 走看看