基于visual Studio2013解决C语言竞赛题之1071打印工资

时间:2023-03-08 18:42:55



基于visual Studio2013解决C语言竞赛题之1071打印工资

题目

基于visual Studio2013解决C语言竞赛题之1071打印工资

解决代码及点评



/************************************************************************/
/*
建立一个链表,每个结点包括的成员为:职工号、工资。用new函数开辟新结点。
要求链表包括5个结点,从键盘输入结点中的有效数据。然后把这些结点的数据打印出来。
要求用函数creat来建立链表,用list函数来输出数据。这5个职工的职工号是101,103,105,107,109。 */
/************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h> typedef struct student STU;
struct student
{
int num;
int GZ;
struct student * next;
};
STU * creat71()
{
STU * p=(STU *)malloc(sizeof(STU));
if (p==NULL)
{
return NULL;
}
else
p->next=NULL;
return p;
}
void Insert71(STU * head,int num,int GZ)
{ STU * last=head;
if (last==NULL)
{
return;
}
while(last->next!=NULL)
last=last->next;
STU *p=(STU *)malloc(sizeof(STU));
if (p==NULL)
{
return;
}
else
{
p->num=num;
p->GZ=GZ;
last->next=p;
p->next=NULL; }
}
void DeleteNode71(STU* pre,STU *cur)
{
pre->next=cur->next;
free(cur);
}
void list71(STU *head)
{
STU *p=head->next;
while(p!=NULL)
{
printf("%5d",p->num);
p=p->next;
}
printf("\n");
}
void main()
{
STU * A=creat71();
for (int i=0;i<5;i++)
{
int num;
int GZ;
scanf_s("%d,%d",&num,&GZ);
Insert71(A,num,GZ);
} list71(A);
system("pause");
}

代码编译以及运行

由于资源上传太多,资源频道经常被锁定无法上传资源,同学们可以打开VS2013自己创建工程,步骤如下:

1)新建工程

基于visual Studio2013解决C语言竞赛题之1071打印工资

2)选择工程

基于visual Studio2013解决C语言竞赛题之1071打印工资

3)创建完工程如下图:

基于visual Studio2013解决C语言竞赛题之1071打印工资

4)增加文件,右键点击项目

基于visual Studio2013解决C语言竞赛题之1071打印工资

5)在弹出菜单里做以下选择

基于visual Studio2013解决C语言竞赛题之1071打印工资

6)添加文件

基于visual Studio2013解决C语言竞赛题之1071打印工资

7)拷贝代码与运行

基于visual Studio2013解决C语言竞赛题之1071打印工资

程序运行结果

基于visual Studio2013解决C语言竞赛题之1071打印工资

代码下载

http://download.****.net/detail/yincheng01/6681845

解压密码:c.itcast.cn