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