Program to accept Book details of ‘n’ books as book_title, author, publisher and cost. Assign the accession number to each book in increasing order Display these details as


Program to accept Book details of ‘n’ books as book_title, author,  publisher and cost. Assign the accession number to each book in increasing order Display these details as
1.         Books of a specific author
2.         Books by a specific Publisher
3.         All Books costing Rs. 500 and above.
4.         All Books.                   (Using Structure Array)                                                                  

#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
struct book
{
 int bno,bcost,baccno;
 char bname[20],bpub[20],bauthor[20];
 }p[10];
  int n,i,f,ch;
  char pubname[20],authorname[20];
  clrscr();
  printf("Enter the limit of structure array=");
  scanf("%d",&n);
  for(i=0;i<n;i++)
  {
            printf("Enter the book no=");
            scanf("%d",&p[i].bno);
            flushall();
            printf("Enter the book name=");
            gets(p[i].bname);
            flushall();
            printf("Enter the book author=");
            gets(p[i].bauthor);
            printf("Enter the book publication=");
            flushall();
            gets(p[i].bpub);
            printf("Enter the book cost=");
            scanf("%d",&p[i].bcost);
            printf("Enter the book accession number =");
            scanf("%d",&p[i].baccno);
  }
  while(1)
  {
  printf("\n1.Books of specific author");
  printf("\n2.Books of specific publisher");
  printf("\n3.All books costing Rs 500&above");
  printf("\n4.All books");
  printf("\n5.exit");
  printf("\nEnter the choice=");
  scanf("%d",&ch);
  switch(ch)
  {
            case 1:
             printf("Enter the author name you want=");
             flushall();
             gets(authorname);
             f=0;
             for(i=0;i<n;i++)
             {
             if(strcmp(p[i].bauthor,authorname)==0)
             // if(f==0)
             {
            printf("\nBno=%d\tname=%s\taccession no=%d",p[i].bno,p[i].bname,p[i],p[i].baccno);
             }
   }
             break;
   case 2:
             printf("Enter the publisher name=");
             flushall();
             gets(pubname);
             f=0;
             for(i=0;i<n;i++)
             {
               if(strcmp(p[i].bpub,pubname)==0)
  
               {
            printf("\nbno=%d\tbname=%s\tbpublisher=%s\taccession no=%d",p[i].bno,p[i].bname,p[i].bpub,p[i].baccno);
               }
             }
             break;
  case 3:
             for(i=0;i<n;i++)
             {
              if(p[i].bcost>=500)
              {
              printf("\nbno=%d\nbname=%s\ncost=%d\t accession no=%d",p[i].bno,p[i].bname,p[i].bcost,p[i].baccno);
             }
            }
             break;
  case 4:
             for(i=0;i<n;i++)
             {
               printf("\nbno=%d\nname=%s\nauthor=%s",p[i].bno,p[i].bname,p[i].bauthor);
               printf("\npublisher=%s\ncost=%d\t accession no=%d",p[i].bpub,p[i].bcost);
             }
             break;
  case 5:
             exit(0);
             }

  }
  getch();
}
/* output

Enter the limit of structure array=3

Enter the book no=1
Enter the book name=cprog
Enter the book author=kanetkar
Enter the book publication=nirali
Enter the book cost=150
Enter the book accession number =1001

Enter the book no=2
Enter the book name=dbms
Enter the book author=sharma
Enter the book publication=vision
Enter the book cost=678
Enter the book accession number =1002

Enter the book no=3
Enter the book name=multimedia
Enter the book author=sane
Enter the book publication=bpb
Enter the book cost=785
Enter the book accession number =1003

1.Books of specific author
2.Books of specific publisher
3.All books costing Rs 500&above
4.All books
5.exit
Enter the choice=1
Enter the author name you want=sharma

Bno=2   name=dbms       accession no=2
1.Books of specific author
2.Books of specific publisher
3.All books costing Rs 500&above
4.All books
5.exit
Enter the choice=2
Enter the publisher name=nirali

bno=1   bname=cprog     bpublisher=nirali       accession no=1001
1.Books of specific author
2.Books of specific publisher
3.All books costing Rs 500&above
4.All books
5.exit
Enter the choice=3

bno=2
bname=dbms
cost=678         accession no=1002
bno=3
bname=multimedia
cost=785         accession no=1003
1.Books of specific author
2.Books of specific publisher
3.All books costing Rs 500&above
4.All books
5.exit
Enter the choice=4

bno=1
name=cprog
author=kanetkar
publisher=nirali
cost=150         accession no=1798
bno=2
name=dbms
author=sharma
publisher=vision
cost=678         accession no=1798
bno=3
name=multimedia
author=sane
publisher=bpb
cost=785         accession no=1798
1.Books of specific author
2.Books of specific publisher
3.All books costing Rs 500&above
4.All books
5.exit
Enter the choice=*/