FY_BCA_C_SLIP 1_2



Slip no : 1_2 write a menu driven prog to accept and display book info of libarary (using struture)
-    Add book information
-   Dispaly bookinformation
-   Exit


#include<conio.h>
#include<stdio.h> struct library

{
int bid;
char bname[20],aname[20]; int cost;

}l[20];

void accept(struct library lib[],int n)
{
int i;


for(i=0;i<n;i++)


{


printf("\n Enter book id : ");


scanf("%d",&lib[i].bid);


printf("\n Enter book name : ");


scanf("%s",lib[i].bname);


printf("\n Enter author name : ");


scanf("%s",lib[i].aname);


printf("\n Enter book cost : ");


scanf("%d",&lib[i].cost);

}
}




void display(struct library lib[],int n)
{
int i; printf("\nbid\tbname\tanme\tcost\n"); for(i=0;i<n;i++)

{
printf("\n%d\t%s\t%s\t%d",lib[i].bid,lib[i].bname,lib[i].aname,lib[i].cost);
}
}

int main()
{
int no,ch; clrscr();





do
{
printf("\n 1.Add book \n 2.display : \n 0.exit"); printf("\n Enter your choice : "); scanf("%d",&ch);
switch(ch)
{
case 1:
printf("\n Enter how many books "); scanf("%d",&no);
accept(l,no);
break;
case 2:
display(l,no);
break; case 0: break;

default: printf("\n Inavlid choice ");
}
}while(ch!=0);
getch();

}


No comments:

Post a Comment