Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ///Home Work 15 @Nurnobi shanto
- #include<stdio.h>
- #include<stdlib.h>
- typedef struct products
- {
- char name[15];
- char code[12];
- float price;
- struct products *next;
- } p;
- p *head = NULL;
- p *temp = NULL;
- void inserInformation()
- {
- printf("Enter number of total products:");
- int i,n;
- scanf("%d",&n);
- for(i=0; i<n; i++)
- {
- printf("\nEnter products information: #%d\n",i+1);
- p *newStd;
- newStd= (p*)malloc(sizeof(p));
- printf("Enter Name:");scanf("%s", &newStd-> name);
- printf("Enter Product code:");scanf("%s", &newStd-> code);
- printf("Enter products Price:");scanf("%f", &newStd-> price);
- newStd->next=NULL;
- if(head==NULL)
- {
- head=newStd;
- }
- else
- {
- temp=head;
- while(temp->next!=NULL)
- {
- temp=temp->next;
- }
- temp->next=newStd;
- }
- }
- }
- void printInformation()
- {
- printf("\n---------Show products Information:---------\n");
- temp=head;
- int c=1;
- while(temp != NULL)
- {
- printf("\nDisplay products information: #%d\n",c++);
- printf("Name: %s\n",temp-> name);
- printf("ICode: %s\n",temp-> code);
- printf("Price: %.2f\n",temp-> price);
- temp= temp-> next;
- }
- }
- int main()
- {
- inserInformation();
- printInformation();
- return 0;
- }
Add Comment
Please, Sign In to add comment