C Program to Read and Display Data Using Structures

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



Source Code
#include<stdio.h>
struct book
{
    char book_name[20];
    int bookid;
    int book_price;
}b[3];

int main()
{
    int i;
    for(i=0;i<3;i++)
    {
        printf("Enter details for book %d :",i+1);
        scanf("%s %d %d", b[i].book_name,&b[i].bookid,&b[i].book_price);
    }
    printf("\nDetails of books :\n");
    for(i=0;i<3;i++)
    {
        printf("%s %d %d\n", b[i].book_name,b[i].bookid,b[i].book_price);
    }
}
Output
Enter details for book 1 :PCI 101 300
Enter details for book 2 :BCC 102 350
Enter details for book 3 :WPD 103 250

Details of books :
PCI 101 300
BCC 102 350
WPD 103 250





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