-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathPROG_23.C
44 lines (40 loc) · 781 Bytes
/
PROG_23.C
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// Linked list traversing
#include<stdio.h>
#include<stdlib.h>
#define NULL 0
struct linked_list
{
int num;
struct linked_list *next;
};
typedef struct linked_list node;
int main()
{
int n,i;
node *start,*ptr;
printf("how many data : ");
scanf("%d",&n);
printf("insert %d data : ",n);
start = (node *)malloc(sizeof(node));
ptr = start;
for(i=1;i<=n;i++)
{
scanf("%d",&ptr->num);
if(i!=n)
{
ptr->next = (node *)malloc(sizeof(node));
ptr = ptr->next;
}
else
ptr->next = NULL;
}
ptr = start;
printf("displaying items : ");
for(i=1;i<=n;i++)
{
printf("%d ",ptr->num);
ptr = ptr->next;
}
printf("\n");
return 0;
}