Computer Science, asked by benjamin4457, 1 year ago

Explain the concept of array of structure with suitable c prg

Answers

Answered by raksha1993
0
Hi
--》if we need the details of 100 books,then it is difficult to declare 100 structure variables using this methods,but this problem can be solved by array of structure.
--》array of stucture means collection of structure,it means array storing different type of structure member variables.
●syntax:
struct book
{
int pages;
float price;
char title[20];
}book [100];
--》so for each book we can enter details of pages,price,title.so we can create database of 100 books
●programme to enter information of 3 books:
struct book
{
int pages;
float proce;
char title[20];
}book [3];
void main ()
{
clrscr ();
for(i=0;i <3;i++)
{
printf("enter book detail %d",i);
printf("enter book title");
gets (book [i].name);
printf("enter pages");
scanf ("%d",book [i].pages);
printf("enter price");
scanf ("%f",book[i].price);
}
for (i=0;i <3;i++)
{ printf("book title");
printf("name=%'s, book[i].name);
printf("pages=%'d, book[i].pages);
printf("price=%'f, book[i].price);
}
getch ();
}
-->Output:
enter book detail 1
enter book title ACP
enter pages 20
enter price 50
enter book detail 2
enter book title BE
enter pages 25
enter price 45
enter book detail 3
enter book title CPD
enter pages 30
enter price 55

Similar questions
Math, 8 months ago