c语言基础编程题求解

2025-02-25 17:01:25
推荐回答(1个)
回答1:

#include

#include

#define stu struct student

stu

{ char name[20];

  int age;

  int wage;

  stu *next;

};

stu *creat( void )

{ stu *p,*q,*h;

  int i;

  for(i=0; i<3; i++)

  { p=(stu*)malloc(sizeof(stu));

    scanf("%s%d%d",p->name,&(p->age),&(p->wage));

    if(i==0)h=q=p;

    else q->next=p,q=p;

  }

  q->next=NULL;

  return h;

}

void output( stu *p )

{ while ( p != NULL )

  { printf( "%s: ", p->name );

    printf( "age=%d wage=%d\n", p->age, p->wage );

    p = p->next;

  }

}

int main()

{ stu *p;

  p = creat( );

  output( p );

}