十年网站开发经验 + 多家企业客户 + 靠谱的建站团队
量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决
#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("
");
}