Advertisement
asiffff

Linked list

Feb 6th, 2019
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. struct node
  4. {
  5. int id;
  6. double prize;
  7. struct node *next;
  8. }*start=NULL;
  9. void cre()
  10. {
  11. struct node *c,*n;
  12. int a,i;
  13. printf("Enter book number:\n");
  14. scanf("%d",&a);
  15. for(i=0;i<a;i++)
  16. {
  17. n=(struct node*)malloc(sizeof(struct node));
  18. printf("Enter book id:\n");
  19. scanf("%d",&n->id);
  20. printf("Enter book prize\n");
  21. scanf("%lf",&n->prize);
  22. n->next=NULL;
  23. if(start == NULL)
  24. {
  25. start=n;
  26. c=n;
  27. }
  28. else
  29. {
  30. c->next = n;
  31. c=n;
  32. }
  33.  
  34. }
  35.  
  36. }
  37. void dis()
  38. {
  39. struct node *c;
  40. c=start;
  41. while(c!=NULL)
  42. {
  43. printf("Id-->%d-->%.1lf-->",c->id,c->prize);
  44. c=c->next;
  45. }
  46. printf("NULL");
  47. }
  48. void max()
  49. {
  50. struct node *c;
  51. c=start;
  52. double max=0;
  53. while(c!=NULL)
  54. {
  55. if(max<c->prize)
  56. {
  57. max=c->prize;
  58. }
  59. c=c->next;
  60. }
  61. printf("\nHighest prize is %.1lf\n",max);
  62. }
  63. int main()
  64. {
  65. cre();
  66. dis();
  67. max();
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement