C Program to Display the Details of Book Using Structure

In this program, you'll learn to declare structure "book" having data member as book_name, book_id, book_price, author. Accept this data for 3 books and display it.

Source Code

struct book
    char book_name[20];
    int bookid;
    float book_price;
    char author[15];

int main()
    struct book b[3];
    int i;
    for(i=0; i<3; i++)
        printf("Enter details of book #%d\n", i+1);
        printf("Enter book id: ");
        scanf("%d", &b[i].bookid);
        printf("Enter book name: ");
        scanf("%s", b[i].book_name);
        printf("Enter book author: ");
        scanf("%s", b[i].author);
        printf("Enter book price: ");
        scanf("%f", &b[i].book_price);

    for(i=0; i<3; i++)
        printf("\nBook %d.............\n\n", i+1);
        printf("Book Id: %d\n", b[i].bookid);
        printf("Book Name: %s\n", b[i].book_name);
        printf("Book Author: %s\n", b[i].author);
        printf("Book price: %f", b[i].book_price);
    return 0;
Enter details of book #1
Enter book id: 101
Enter book name: LetUsC
Enter book author: Kanetkar
Enter book price: 350.20
Enter details of book #2
Enter book id: 102
Enter book name: ANSI_C
Enter book author: Balgurusamy
Enter book price: 300.78
Enter details of book #3
Enter book id: 103
Enter book name: OperatingSystem
Enter book author: Godbole
Enter book price: 295.67
Book 1.............
Book Id: 101
Book Name: LetUsC
Book Author: Kanetkar
Book price: 350.200012

Book 2.............
Book Id: 102
Book Name: ANSI_C
Book Author: Balgurusamy
Book price: 300.779999

Book 3.............
Book Id: 103
Book Name: OperatingSystem
Book Author: Godbole
Book price: 295.670013

"Coding Hub - Learn to code" app now available on Google Play Store