From 45ad18152abcfcb97382f56cd58e72b594b1a01a Mon Sep 17 00:00:00 2001 From: Pallavi Kathait Date: Thu, 3 Oct 2024 20:15:22 +0530 Subject: [PATCH] Create LinlList.c Added a new program LinkList.c --- C Language/LinlList.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 C Language/LinlList.c diff --git a/C Language/LinlList.c b/C Language/LinlList.c new file mode 100644 index 0000000..f6d0049 --- /dev/null +++ b/C Language/LinlList.c @@ -0,0 +1,36 @@ +#include +struct node +{ + int data; + struct node *next; +}; + +void main() +{ + struct node *p, *head; + int n, i; + printf("How many nodes to be created\n"); + scanf("%d", &n); + for (i = 0; i < n; i++) + { + if (i == 0) + { + head = (struct node *)malloc(sizeof(struct node)); + p= head; + } + else + { + p->next = (struct node *)malloc(sizeof(struct node)); + printf("Enter the value: "); + scanf("%d", &p->next->data); + } + p = p->next; + } + p->next = NULL; + p = head; + while (p->next != NULL) + { + printf("%d", p->data); + p = p->next; + } +}