当前位置:三九宝宝网 → 宝宝教育 → 教学论文 → 正文

c语言创建一个储存10个数字的链表并倒序输出

更新:12-28 整理:39baobao.com
字体:

[C语言由键盘输入10个整数倒序输出]#include <stdio.h> int main() { int numbers[10]; int count; for(count=0;count<=9;count++) { printf("请输入第%d个数:", count); scanf("%d", &numbers[count]); } for(count=...+阅读

#include

#include

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 {

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

}

本文地址:https://www.39baobao.com/show/29_16390.html

以上内容来自互联网,请自行判断内容的正确性。若本站收录的信息无意侵犯了贵司版权,请联系我们,我们会及时处理和回复,谢谢.

以下为关联文档:

C语言输入十个数将其倒序排列使用函数嵌套的方法#include <stdio.h> #define N 5 void input(int [ ], int); void output(int [ ], int); void sort(int [ ], int); int minpos(int [ ], int, int); void swap(int [ ], i...