Advertisement
afrinahoque

Summer'19 A1

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