mdnurnobihosen

datastructure15

Jun 21st, 2019
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.48 KB | None | 0 0
  1. ///Home Work 15 @Nurnobi shanto
  2. #include<stdio.h>
  3. #include<stdlib.h>
  4. typedef struct products
  5. {
  6.     char name[15];
  7.     char code[12];
  8.     float price;
  9.     struct products *next;
  10. } p;
  11. p *head = NULL;
  12. p *temp = NULL;
  13.  
  14. void inserInformation()
  15.     {
  16.     printf("Enter number of total products:");
  17.     int i,n;
  18.     scanf("%d",&n);
  19.     for(i=0; i<n; i++)
  20.     {
  21.         printf("\nEnter products information: #%d\n",i+1);
  22.         p *newStd;
  23.         newStd= (p*)malloc(sizeof(p));
  24.  
  25.         printf("Enter Name:");scanf("%s", &newStd-> name);
  26.         printf("Enter Product code:");scanf("%s", &newStd-> code);
  27.         printf("Enter products Price:");scanf("%f", &newStd-> price);
  28.  
  29.  
  30.         newStd->next=NULL;
  31.         if(head==NULL)
  32.         {
  33.             head=newStd;
  34.         }
  35.           else
  36.         {
  37.             temp=head;
  38.             while(temp->next!=NULL)
  39.             {
  40.                 temp=temp->next;
  41.             }
  42.                temp->next=newStd;
  43.         }
  44.     }
  45.  
  46.     }
  47.  
  48. void printInformation()
  49.     {
  50.         printf("\n---------Show products Information:---------\n");
  51.         temp=head;
  52.         int c=1;
  53.     while(temp != NULL)
  54.     {
  55.         printf("\nDisplay products information: #%d\n",c++);
  56.         printf("Name: %s\n",temp-> name);
  57.         printf("ICode: %s\n",temp-> code);
  58.         printf("Price: %.2f\n",temp-> price);
  59.         temp= temp-> next;
  60.     }
  61.  
  62.     }
  63.  
  64. int main()
  65. {
  66.     inserInformation();
  67.     printInformation();
  68.     return 0;
  69. }
Add Comment
Please, Sign In to add comment