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_first()
- {
- node *N=(node*)malloc(sizeof(node));
- scanf("%d", &N->a);
- N->next=NULL;
- if (head==NULL)
- {
- head=N;
- return;
- }
- else
- {
- N->next=head;
- head=N;
- return;
- }
- }
- void display()
- {
- node *list=head;
- while(list!=NULL)
- {
- printf("%d\n", list->a);
- list=list->next;
- }
- }
- int main()
- {
- int i,n;
- scanf("%d", &n);
- for(i=0; i<n; i++)
- {
- insert_at_first();
- }
- display();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement