First time here? Checkout the FAQ!
x
menu search
brightness_auto
more_vert

Write a program to read Title, Author and Price of 5 books using array of structures. Display the records in ascending order of Price.

thumb_up_off_alt 0 like thumb_down_off_alt 0 dislike

1 Answer

more_vert
 
verified
Best answer
#include <stdio.h>
//#include <conio.h>
struct book
{
int price;
char title[80];
char author[80];
};
void accept(struct book list[80]); //func declare
void display(struct book list[80]);
void bsortAsc(struct book list[80]);
void main()
{
struct book data[20];
int n;
//clrscr();
accept(data); //func call
bsortAsc(data);
display(data);
//getch();
}
void accept(struct book list[5]) // func initialize
{
int i;
for (i = 0; i <5; i++)
{
printf("\nEnter title : ");
scanf("%s", &list[i].title);
printf("Enter Author name: ");
scanf("%s",&list[i].author);
printf("Enter price : ");
scanf("%d", &list[i].price);
}
}
void display(struct book list[80])
{
int i;
printf("\n\nTitle\t\tAuthor\t\tprice\n");
printf("-------------------------------------\n");
for (i = 0; i<5; i++)
{
printf("%s\t\t%s\t\t%d\n", list[i].title, list[i].author, list[i].price);
}
}
void bsortAsc(struct book list[80])
{
int i, j;
struct book temp;
for (i = 0; i <5 ; i++)
{
for (j = 0; j < (5 -i); j++)
{
if (list[j].price >list[j + 1].price)
{
temp = list[j];
list[j] = list[j + 1];
list[j + 1] = temp;
}
}
}}
thumb_up_off_alt 0 like thumb_down_off_alt 0 dislike
more_vert
Run programm : https://onlinegdb.com/yT6lyvDEy
...