链表编写链表将数字倒序输出的C语言程序。(我们C语言老师讲的!)-创新互联
#include "stdio.h"
#include "stdlib.h"
struct shao{
int num;
struct shao *next;
};
void main()
{
int n;
struct shao *head=NULL,*p1,*p2;
printf("请输入要参加几个数:");
scanf("%d",&n);
while(n<=0)
{
printf("错误!请重新输入:");
scanf("%d",&n);
}
p1=(struct shao*)malloc(sizeof(struct shao));
p1->next=NULL;
head=p1;
printf("请输入一个数:");
scanf("%d",&p1->num);
for(int i=2;i<=n;i++)
{
p2=(struct shao*)malloc(sizeof(struct shao));
printf("请输入一个数:");
scanf("%d",&p2->num);
head=p2;
p2->next=p1;
p1=p2;
}
printf("倒序的结果是:");
for(i=0;head!=NULL;i++)
{
printf("%d ",head->num);
head=head->next;
}
printf("
");
}
文章题目:链表编写链表将数字倒序输出的C语言程序。(我们C语言老师讲的!)-创新互联
文章网址:http://scyanting.com/article/djidsc.html