#include <stdio.h>
#include <stdlib.h>
struct node
{
int a;
node *next;
};
void output(node *p)
{
if (p != NULL)
{
output(p->next);
printf ("%d ", p->a);
}
}
int main()
{
int a, n;
node *head = NULL, *p;
printf("请输入数字个数:");
scanf("%d", &n);
printf("请输入数字:");
for (int i = 0; i < n; i++)
{
scanf("%d", &a);
if (head == NULL)
{
head = (node *)malloc(sizeof(node));
head->a = a;
p = head;
}
else
{
p->next = (node *)malloc(sizeof(node));
p = p->next;
p->a = a;
}
}
p->next = NULL;
printf("倒序输出数字:");
output(head);
printf("\n");
}
追问这个程序运行起来有好多bug 能不能给修改一下?
非常感谢!
追答什么bug?
追问![](https://video.ask-data.xyz/img.php?b=https://iknow-pic.cdn.bcebos.com/0823dd54564e9258adae96929f82d158ccbf4e37?x-bce-process=image%2Fresize%2Cm_lfit%2Cw_600%2Ch_800%2Climit_1%2Fquality%2Cq_85%2Fformat%2Cf_auto)
追答#include <stdio.h>
#include <stdlib.h>
typedef struct node
{
int a;
node *next;
}node;
void output(node *p)
{
if (p != NULL)
{
output(p->next);
printf ("%d ", p->a);
}
}
int main()
{
int a, n, i;
node *head = NULL, *p;
printf("请输入数字个数:");
scanf("%d", &n);
printf("请输入数字:");
for (i = 0; i < n; i++)
{
scanf("%d", &a);
if (head == NULL)
{
head = (node *)malloc(sizeof(node));
head->a = a;
p = head;
}
else
{
p->next = (node *)malloc(sizeof(node));
p = p->next;
p->a = a;
}
}
p->next = NULL;
printf("倒序输出数字:");
output(head);
printf("\n");
return 0;
}
你用的什么编译器?不知道这样能过不?不行你就用另外一位仁兄的吧。。。
本回答被网友采纳