c语言基础编程题求解 50

3.编写程序,建立一个有3个结点的单向链表,每个结点包含姓名、年龄和工资。编写两个函数,一个用于建立链表,另一个用来输出链表。#include<stdio.h>#incl... 3. 编写程序,建立一个有3个结点的单向链表,每个结点包含姓名、年龄和工资。编写两个函数,一个用于建立链表,另一个用来输出链表。
#include <stdio.h>
#include <malloc.h>
#define stu struct student
stu
{
char name[20];
int age;
int wage;
stu *next;
};
stu *creat( void )
{

}
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 );
}
要求:1)上述程序文件名E4-8.C的文件,存放在E盘根目录下;
2)把建立链表的函数creat补充完整,数据输入和链表建立在函数中实现;
3)不得修改函数creat外的任何语句。
展开
 我来答
听不清啊
高粉答主

2020-06-30 · 说的都是干货,快来关注
知道顶级答主
回答量:7.8万
采纳率:89%
帮助的人:1.8亿
展开全部

#include <stdio.h>

#include <malloc.h>

#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 );

}

推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式