Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<stdlib.h>
- typedef struct node
- {
- int a;
- struct node *next;
- }node;
- node *head=NULL;
- void insert_at_last()
- {
- node *N=(node*)malloc(sizeof(node));
- scanf(" %d", &N->a);
- N->next=NULL;
- node *list;
- if(head==NULL)
- {
- head=N;
- return;
- }
- else
- {
- while(list->next!=NULL)
- {
- list=list->next;
- }
- list->next=N;
- list=N;
- }
- }
- void display()
- {
- node *list=head;
- while(list!=NULL)
- {
- printf("Data: %d\n", list->a);
- list=list->next;
- }
- }
- int main()
- {
- int i,n;
- scanf("%d", &n);
- for(i=0; i<n; i++)
- {
- insert_at_last();
- }
- display();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement