fork download
  1. #include<stdio.h>
  2. struct book
  3. {
  4. char title[50];
  5. char author[50];
  6. int pages;
  7. float price;
  8.  
  9. };
  10. int main(){
  11. float no;
  12. printf("Enter number of books in the library\n");
  13. scanf("%f",&no);
  14. struct book a[50];
  15. if(no<=0)
  16. printf("No books in the library");
  17. else{
  18. for(int i=0;i<no;i++){
  19. printf("Enter details for book %d\n",i+1);
  20. printf("Enter book name\n");
  21. fgets(a[i].title,50,stdin);
  22. printf("Enter book author\n");
  23. fgets(a[i].author,50,stdin);
  24. printf("Enter number of pages in the book\n");
  25. scanf("%d",&a[i].pages);
  26. printf("Enter book price\n");
  27. scanf("%f",&a[i].price);
  28.  
  29. }}
  30. }
Success #stdin #stdout 0s 9416KB
stdin
-8
stdout
Enter number of books in the library
No books in the library