鱼C论坛

 找回密码
 立即注册
查看: 2523|回复: 8

C语言

[复制链接]
发表于 2020-5-16 16:09:01 | 显示全部楼层
试着写了下
  1. #include<stdio.h>
  2. #include<malloc.h>

  3. struct People
  4. {
  5.         char name[9];
  6.         float te;
  7.         int ju;
  8.         struct People *next;
  9. };

  10. void getpeople(struct People *person)
  11. {
  12.         scanf("%s %f %d",person->name,&person->te,&person->ju);
  13. }

  14. void outpeople(struct People *person)
  15. {
  16.         printf("%s\n",person->name);
  17. }

  18. void addpeople(struct People **head)
  19. {        struct People *person,*rear;
  20.         person=(struct people *)malloc(sizeof(struct People));
  21.         if(person==NULL)
  22.         {
  23.                 fprintf(stderr,"申请内存失败!\n");
  24.         }
  25.         getpeople(person);

  26.         if(*head==NULL)
  27.         {
  28.                 *head=person;
  29.                 person->next=NULL;
  30.         }
  31.         else
  32.         {
  33.          
  34.                 rear->next=person;
  35.                 person->next=NULL;
  36.         }
  37.         rear=person;
  38. }
  39. int main()
  40. {
  41.         int n,i,count=0;
  42.         scanf("%d",&n);
  43.         struct People *head=NULL;
  44.         struct People *person;
  45.         for(i=0;i<n;i++)
  46.         {
  47.                 addpeople(&head);
  48.         }
  49.         person=head;
  50.         putchar('\n');
  51.         while(person!=NULL)
  52.         {
  53.                 if((person->te>=37.5)&&(person->ju==1))
  54.                 {
  55.                         outpeople(person);
  56.                         person=person->next;
  57.                         count++;
  58.                         continue;
  59.                 }
  60.                 person=person->next;
  61.         }
  62.         printf("%d\n",count);
  63. }
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 2 反对 0

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-11-3 08:01

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表