C File =>
/* Write a C program to create a structure named book (book_name, author_name and price) and display all book details having price > 500 in a proper format by passing the structure array as function argument. */
#include<stdio.h>
typedef struct book
{
char name[50];
char author[50];
float price;
};
int main()
{
struct book b[50];
int i,n;
printf("\n How many books? ");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("\n Enter book name%d : ",i+1);
scanf("%s",b[i].name);
printf("\n Enter author%d : ",i+1);
scanf("%s",b[i].author);
printf("\n Enter Price%d : ",i+1);
scanf("%f",&b[i].price);
}
void display(struct book b[50])
{
int i;
printf("\n\n Details of book :");
for(i=0;i<n;i++)
{
if(b[i].price>500)
{
printf("\n\n Book name : %s",b[i].name);
printf("\n Author : %s",b[i].author);
printf("\n Price : %f",b[i].price);
}
}
}
// calling function
display(b);
return 0;
}
Comments
Post a Comment
Please do not enter any spam link in message.