Advertisement
nuray__alam

Problem 1

Dec 8th, 2019
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.85 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. typedef struct node
  4. {
  5.     int value;
  6.     struct node *next;
  7.  
  8. }node;
  9. node *head=NULL;
  10.  
  11. void insertlast(int x)
  12. {
  13.     node *n=(node*)malloc(sizeof(node));
  14.     n->next=NULL;
  15.     n->value=x;
  16.     node *list=head;
  17.     if(head==NULL) head=n;
  18.     else{
  19.         while(list->next!=NULL)
  20.         {
  21.             list=list->next;
  22.         }
  23.         list->next=n;
  24.     }
  25.     return;
  26.  
  27. }
  28.  
  29. void display()
  30. {
  31.     node *list=head;
  32.      printf("Data entered in the list:\n");
  33.     while(list!=NULL){
  34.         printf("Data = %d\n",list->value);
  35.         list=list->next;
  36.     }
  37. }
  38. int main()
  39. {
  40.     int i,n,x;
  41.  
  42.     printf("Enter how many value you want to enter: ");
  43.     scanf("%d",&n);
  44.     printf("\n\n");
  45.     for(i=1;i<=n;i++)
  46.     {
  47.         scanf("%d",&x);
  48.         insertlast(x);
  49.     }
  50.    display();
  51.     return 0;
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement