Advertisement
afrinahoque

balalala

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