write a c program to read and print information of a book using structure.
Mohammed
Guys, does anyone know the answer?
get write a c program to read and print information of a book using structure. from screen.
Write a program to create structure Book Detail.Display the book details in proper format by passing the structure as function argument.
Home > BCA Projects > C Language Project sem 2 [F.Y.B.C.A.(2014-15)] >
Write a program to create structure Book Detail.Display the book details in proper format by passing the structure as function argument.
#include#include#include#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 n,i; clrscr();
printf("Enter the Numbers of Books:");
for(i=0;iscanf("%d",&n); printf("\n");
{
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,n); getch(); }
void output(struct bookdetail v[],int n)
for(i=0;i{ int i,t=1;
{ 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"); } } Output:
Enter The Numbers of Books:3
=:Book 1 Detail:=
Enter the Book Name:
letusc
Enter the Author of Book:
Y.Kanetkar
Enter the Pages of Book:
850
Enter the Price of Book:
160 =:Book 2 Detail:=
Enter the Book Name:
IC
Enter the Author of Book:
Peter
Enter the Pages of Book:
200
Enter the Price of Book:
70 =:Book 3 Detail:=
Enter the Book Name:
ANSIC
Enter the Author of Book:
Balaguruswami
Enter the Pages of Book:
450
Enter the Price of Book:
100 Book No.1
Book 1 Name is=Letusc
Book 1 Author is=Y.Kanetkar
Book 1 Pages is =850
Book 1 Price is =160.000000
Book No.2 Book 2 Name is=IC
Book 2 Author is=Peter
Book 2 Pages is=200
Book 2 Price is =70.000000
Book No.3
Book 3 Name is=ANSIC
Book 3 Author is=Balaguruswami
Book 3 Pages is=450
Book 3 Price is=100.000000
Comments
Programmingtutorials4u.com
See relevant content for Programmingtutorials4u.com
PROGRAMMINGTUTORIALS4U.COM
स्रोत : ww1.programmingtutorials4u.com
Write a C program to create Book Details using structure
I have used Code::blocks 12 compiler for debugging purpose. But you can use any C programming language compiler as per your availability.
Write a C program to create Book Details using structure
July 12, 2021 by Rohit Mhatre
Introduction
I have used Code::blocks 12 compiler for debugging purpose. But you can use any C programming language compiler as per your availability.
#include#include#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:");
for(i=0;iscanf("%d",&num); printf("\n");
{
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)
for(i=0;i{ int i,t=1;
{ 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
Also read,
Flipkart VS Amazon Comparison
Guys, does anyone know the answer?