belongs to collection: All structure C programs with examples
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"); } }
Enter the Book Name:
book1
Enter the Author of Book:
John
Enter the Pages of Book:
200
Enter the Price of Book:
500
=:Book 2 Detail:=
book2
Mike
100
300
Book No.1
Book 1 Name is=book1
Book 1 Author is=John
Book 1 Pages is=200
Book 1 Price is=500.000000
Book No.2
Book 2 Name is=book2
Book 2 Author is=Mike
Book 2 Pages is=100
Book 2 Price is=300.000000
total answers (1)
start bookmarking useful questions and collections and save it into your own study-lists, login now to start creating your own collections.
I have used Code::blocks 12 compiler for debugging purpose. But you can use any C programming language compiler as per your availability.
Result:
Enter the Book Name:
book1
Enter the Author of Book:
John
Enter the Pages of Book:
200
Enter the Price of Book:
500
=:Book 2 Detail:=
Enter the Book Name:
book2
Enter the Author of Book:
Mike
Enter the Pages of Book:
100
Enter the Price of Book:
300
Book No.1
Book 1 Name is=book1
Book 1 Author is=John
Book 1 Pages is=200
Book 1 Price is=500.000000
Book No.2
Book 2 Name is=book2
Book 2 Author is=Mike
Book 2 Pages is=100
Book 2 Price is=300.000000
need an explanation for this answer? contact us directly to get an explanation for this answer