CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
可用分押宝游戏火热进行中... 专题改版:Java Web 专题
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  C/C++ >  C语言

请大家帮忙试试这个链表哪里错了100分

楼主mingsi(Mingsi)2005-06-04 14:23:37 在 C/C++ / C语言 提问

#define   NULL   0  
  #define   LEN   sizeof(struct   student)  
  struct   student  
  {long   id;  
  int   s1,s2,s3;  
  float   aver;  
  struct   student   *next;  
  };  
  int   n;  
  struct   student   *creat()  
  {struct   student   *head;  
  struct   student   *p1,*p2;  
  n=0;  
   
  p1=p2=(struct   student   *)malloc(LEN);  
  scanf("%ld%d%d%d",&p1->id,&p1->s1,&p1->s2,&p1->s3);  
  p1->aver=(p1->s1+p1->s2+p1->s3)/3;  
   
  head=NULL;  
   
  while(p1->id!=0)  
      {n=n+1;  
        if   (n==1)head=p1;  
        else   p2->next=p1;  
        p2=p1;  
        p1=(struct   student   *)malloc(LEN);  
        scanf("%ld%d%d%d",&p1->id,&p1->s1,&p1->s2,&p1->s3);  
        p1->aver=(p1->s1+p1->s2+p1->s3)/3;  
   
        }  
  p2->next=NULL;  
  return(head);  
  }  
  void   print(head)  
  struct   student   *head;  
  {struct   student   *p;  
    int   i;  
    p=head;  
    if   (head!=NULL)  
        for   (i=1;i<=n;i++)  
          {printf("%ld     %d   %d   %d   %f\n",p->id,p->s1,p->s2,p->s3,p->aver);  
            p=p->next;  
          }  
  }  
  main()  
  {  
    print(creat());  
  } 问题点数:0、回复次数:9Top

1 楼herryhuang(Herry)回复于 2005-06-04 14:38:25 得分 0

你的函数呢??????????  
   
  creat函数在哪?另外,换一个名字,这个函数名是标准库函数。Top

2 楼mingsi(Mingsi)回复于 2005-06-04 14:49:48 得分 0

函数在这里~struct   student   *creat()  
  换了也不行~我输入两组数据  
  1   2   3   4  
  2   3   4   5  
  0   0   0   0   (遇零结束)  
  结果输出是:  
  0   0   0   0   0.000000  
   
  178061594   395   112   0.000000  
  Top

3 楼mccxj(老鼠不逛街)回复于 2005-06-04 15:00:32 得分 0

#include   <stdio.h>  
  #include   <stdlib.h>  
   
  #define   NULL   0  
  #define   LEN   sizeof(struct   student)  
   
  struct   student  
  {  
  long   id;  
  int   s1,s2,s3;  
  float   aver;  
  struct   student   *next;  
  };  
  struct   student   *head;  
  int   n;  
   
  struct   student   *creat()  
  {  
  struct   student   *head;  
  struct   student   *p1,*p2;  
  n=0;  
   
  p1=(struct   student   *)malloc(LEN);  
  p2=(struct   student   *)malloc(LEN);  
  scanf("%ld%d%d%d",&p1->id,&p1->s1,&p1->s2,&p1->s3);  
  p1->aver=float(p1->s1+p1->s2+p1->s3)/3;  
   
  head=NULL;  
   
  while(p1->id!=0)  
  {  
  n=n+1;  
  if   (n==1) head=p1;  
  else   p2->next=p1;  
  p2=p1;  
  p1=(struct   student   *)malloc(LEN);  
  scanf("%ld%d%d%d",&p1->id,&p1->s1,&p1->s2,&p1->s3);  
  p1->aver=float(p1->s1+p1->s2+p1->s3)/3;  
          }  
  p2->next=NULL;  
  return(head);  
  }  
   
  void   print(student   *head)  
  {  
  struct   student   *p;  
  int   i;  
  p=head;  
  if   (head!=NULL)  
  for   (i=1;i<=n;i++)  
          {  
  printf("%ld     %d   %d   %d   %f\n",p->id,p->s1,p->s2,p->s3,p->aver);  
  p=p->next;  
          }  
  }  
   
  int   main()  
  {  
  print(creat());  
  return   0;  
  }  
  。。。你的格式和设计似乎有点问题。。Top

4 楼mccxj(老鼠不逛街)回复于 2005-06-04 15:02:16 得分 0

1   2   3   4  
  2   3   4   5  
  0   0   0   0   (遇零结束)  
  1     2   3   4   3.000000  
  2     3   4   5   4.000000  
  Press   any   key   to   continue  
  上面是测试结果。。环境:vc6.0Top

5 楼zhousqy(标准C匪徒)(甩拉,甩拉)回复于 2005-06-04 15:20:10 得分 0

运行结果,基本马马虎虎,没什么错阿。Top

6 楼mingsi(Mingsi)回复于 2005-06-04 15:39:56 得分 0

。。。难道是我的tc有问题~~~????Top

7 楼ice_yezh(椰树)回复于 2005-06-04 16:15:21 得分 0

运行结果没有问题呀!!Top

8 楼darkstar21cn(≮天残≯无畏)(死亡进行时)回复于 2005-06-04 17:05:33 得分 0

结构不太好,改一下:  
   
  struct   student   *creat()  
  {  
  struct   student   *head;  
  struct   student   *p1,*p2;  
  n=0;  
   
  p1=(struct   student   *)malloc(LEN);  
  scanf("%ld%d%d%d",&p1->id,&p1->s1,&p1->s2,&p1->s3);  
  p1->aver=float(p1->s1+p1->s2+p1->s3)/3;  
   
  head=p2=p1;  
   
  while(p1->id!=0)  
  {  
  p1=(struct   student   *)malloc(LEN);  
  scanf("%ld%d%d%d",&p1->id,&p1->s1,&p1->s2,&p1->s3);  
  p1->aver=float(p1->s1+p1->s2+p1->s3)/3;  
                                      p2->next=p1;  
                                      p2=p1;  
                                      n=n+1;  
                    }  
  p2->next=NULL;  
  return(head);  
  }  
   
  void   print(student   *head)  
  {  
    struct   student   *p=head;  
    while   (p!=NULL)  
          {  
  printf("%ld     %d   %d   %d   %f\n",p->id,p->s1,p->s2,p->s3,p->aver);  
  p=p->next;  
          }  
  }Top

9 楼mostideal(三甲)回复于 2005-06-05 13:43:16 得分 0

先顶。。。Top

相关问题

  • 语法错误,分给多点.试试!
  • 您还为做报表发愁吗?试试坏猫报表打印控件吧!
  • 我试试..
  • 我想试试
  • 倒分试试
  • 一道看似简单的面试题,很多人会做错!不信试试
  • 大家帮忙呀!!!我错在那里?????不防行一下试试呀!!!!!!!!!
  • 想不想试试...
  • 放一把试试
  • 你来试试看

关键词

  • 函数
  • null
  • aver
  • struct student
  • head
  • ld
  • scanf
  • malloc
  • len
  • next

得分解答快速导航

  • 帖主:mingsi

相关链接

  • C/C++ Blog
  • C/C++类图书
  • C/C++类源码下载

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
世纪乐知(北京)网络技术有限公司 版权所有, 京 ICP 证 020026 号
北京创新乐知广告有限公司 提供技术支持
Copyright © 2000-2007, CSDN.NET, All Rights Reserved
GongshangLogo