Tech Study

How To Create Book Details Using Structure In C Program

In simple languge a structure is a cluster of variables of different data types under same name.

I have used Code::blocks 12 compiler for debugging purpose. But you can use any C programming language compiler as per your availability.

#include<stdio.h>
#include<string.h>
#define SIZE 20
 
struct bookdetail
{
          char name[20];
          char author[20];
          int pages;
          float price;
 
};
 
void output(struct bookdetail v[],int n);
 
void main()
{
          struct bookdetail b[SIZE];
 
          int num,i;
          printf("Enter the Numbers of Books:");
          scanf("%d",&num);
          printf("\n");
          for(i=0;i<num;i++)
 
          {
 
                   printf("\t=:Book %d Detail:=\n",i+1);
 
                   printf("\nEnter the Book Name:\n");
                   scanf("%s",b[i].name);
 
                   printf("Enter the Author of Book:\n");
                   scanf("%s",b[i].author);
 
                   printf("Enter the Pages of Book:\n");
                   scanf("%d",&b[i].pages);
 
                   printf("Enter the Price of Book:\n");
                   scanf("%f",&b[i].price);
 
          }
 
          output(b,num);
 
}
 
void output(struct bookdetail v[],int n)
 
{
 
          int i,t=1;
 
          for(i=0;i<n;i++,t++)
 
          {
 
                    printf("\n");
 
                   printf("Book No.%d\n",t);
 
                   printf("\t\tBook %d Name is=%s \n",t,v[i].name);
 
                   printf("\t\tBook %d Author is=%s \n",t,v[i].author);
 
                   printf("\t\tBook %d Pages is=%d \n",t,v[i].pages);
 
                   printf("\t\tBook %d Price is=%f \n",t,v[i].price);
 
                   printf("\n");
 
          }
 
}

Result

Write a C program to create Book Details using structure
Write a C program to create Book Details using structure

WE HIGHLY RECOMMENDED  FOR  BEGINNERS TO READ THIS CODING BOOK

6 Best Coding Books for Beginners You Must Read in 2023

Write a C program to Store Information in Structure and Display it

Write a C program to calculate percentage of student using structure

TaggedWrite a C program to create Book Details using structure

Java Final keyword

Introduction : java final keyword The final keyword present in Java programming language is generally used for restricting the user. …

Read more

C++ Memory Management: new and delete

C++ Memory Management We know that arrays store contiguous and the same type of memory blocks, so memory is allocated …

Read more