Program to enter library details of a book, then listing the book details on search. Simple and straightforward.
#include<stdio.h>
#include<string.h>
main()
{
int i,j,n,flag=0;
char title[20];
printf("Enter the value of n\n");
scanf("%d",&n);
struct book
{
char authorname[20];
char bookname[20];
int price;
} b[n];
for(i=0;i<n;i++)
{
printf("Enter the name of the author:\n");
scanf("%s",&b[i].authorname);
printf("Enter the name of the book:\n");
scanf("%s",&b[i].bookname);
printf("Enter the price:\n");
scanf("%d",&b[i].price);
}
printf("Enter the title of the book you want to search\n");
scanf("%s",title);
for(i=0;i<n;i++)
{
if(strcmp(b[i].bookname,title)==0)
{
flag=1;
printf("\n\n\n");
printf("The author of the book is:");
printf("%s",b[i].authorname);
printf("\n");
printf("The price of the book is:");
printf("%d",b[i].price);
}
}
if(flag==0)
printf("The book is not found\n");
}
#include<stdio.h>
#include<string.h>
main()
{
int i,j,n,flag=0;
char title[20];
printf("Enter the value of n\n");
scanf("%d",&n);
struct book
{
char authorname[20];
char bookname[20];
int price;
} b[n];
for(i=0;i<n;i++)
{
printf("Enter the name of the author:\n");
scanf("%s",&b[i].authorname);
printf("Enter the name of the book:\n");
scanf("%s",&b[i].bookname);
printf("Enter the price:\n");
scanf("%d",&b[i].price);
}
printf("Enter the title of the book you want to search\n");
scanf("%s",title);
for(i=0;i<n;i++)
{
if(strcmp(b[i].bookname,title)==0)
{
flag=1;
printf("\n\n\n");
printf("The author of the book is:");
printf("%s",b[i].authorname);
printf("\n");
printf("The price of the book is:");
printf("%d",b[i].price);
}
}
if(flag==0)
printf("The book is not found\n");
}
No comments:
Post a Comment