Write a C program to create Book Details using structure


Introduction

I have used Code::blocks 12 compiler for debugging purpose. But you can use any C programming language compiler as per your availability.


techstudy.org

HP 15 Core i3 7th gen Laptop(4GB, 1TB HDD, Windows 10) | Rs. 31,490

Write a C program to create Book Details using structure


  1. #include<stdio.h>
  2. #include<string.h>
  3. #define SIZE 20
  4.  
  5. struct bookdetail
  6. {
  7. char name[20];
  8. char author[20];
  9. int pages;
  10. float price;
  11.  
  12. };
  13.  
  14. void output(struct bookdetail v[],int n);
  15.  
  16. void main()
  17. {
  18. struct bookdetail b[SIZE];
  19.  
  20. int num,i;
  21. printf("Enter the Numbers of Books:");
  22. scanf("%d",&num);
  23. printf("\n");
  24. for(i=0;i<num;i++)
  25.  
  26. {
  27.  
  28. printf("\t=:Book %d Detail:=\n",i+1);
  29.  
  30. printf("\nEnter the Book Name:\n");
  31. scanf("%s",b[i].name);
  32.  
  33. printf("Enter the Author of Book:\n");
  34. scanf("%s",b[i].author);
  35.  
  36. printf("Enter the Pages of Book:\n");
  37. scanf("%d",&b[i].pages);
  38.  
  39. printf("Enter the Price of Book:\n");
  40. scanf("%f",&b[i].price);
  41.  
  42. }
  43.  
  44. output(b,num);
  45.  
  46. }
  47.  
  48. void output(struct bookdetail v[],int n)
  49.  
  50. {
  51.  
  52. int i,t=1;
  53.  
  54. for(i=0;i<n;i++,t++)
  55.  
  56. {
  57.  
  58. printf("\n");
  59.  
  60. printf("Book No.%d\n",t);
  61.  
  62. printf("\t\tBook %d Name is=%s \n",t,v[i].name);
  63.  
  64. printf("\t\tBook %d Author is=%s \n",t,v[i].author);
  65.  
  66. printf("\t\tBook %d Pages is=%d \n",t,v[i].pages);
  67.  
  68. printf("\t\tBook %d Price is=%f \n",t,v[i].price);
  69.  
  70. printf("\n");
  71.  
  72. }
  73.  
  74. }
  75.  

Result

C language techstudy.org

     





Related Topics




Popular Posts