Write a program to achieve the following: include the relevant header files. a) Define a structure called Books, with the following members: title, author, subject, book_id The title, author and subject should be strings (length 50 each) while book-id should be integer Inside main() function: 1)Declare an array of Books type that has size 5. 2) Accept values from the user and store them in the array in 1 (b)Use the printf() function to display the information in the array.
C Programming Language Structure in C Language (Article) Structure in C Language (Program)
905Program:
#include #include struct Books { char title[50]; char author[50]; char subject[100]; int book_id; }; int main() { int i; struct Books Bookarray[5]; printf("\n Enter Books information \n"); for(i=0; i < 5 ;i++) { printf("Book Title: "); scanf("%s",Bookarray[i].title); printf("Book author: "); scanf("%s",Bookarray[i].author); printf("Book subject: "); scanf("%s",Bookarray[i].subject); printf("Book book_id: "); scanf("%d",&Bookarray[i].book_id); printf(".........Next Book........... \n"); } printf("\n Books information \n"); for(i=0; i < 5 ;i++) { printf( "Book title : %s\n", Bookarray[i].title); printf( "Book author : %s\n", Bookarray[i].author); printf( "Book subject : %s\n", Bookarray[i].subject); printf( "Book book_id : %d\n", Bookarray[i].book_id); } return 0; }
Output:
Enter Books information Book Title: C Book author: RAMBO Book subject: PROGRAMMING Book book_id: 1 .........Next Book........... Book Title: DATABASE Book author: RAMBO Book subject: DATA Book book_id: 2 .........Next Book........... Book Title: JAVA Book author: RAMBO Book subject: PROGRAMMING Book book_id: 3 .........Next Book........... Book Title: SQL Book author: RAMBO Book subject: DATABASE Book book_id: 4 .........Next Book........... Book Title: PHP Book author: RABMBO Book subject: PROGRAMMING Book book_id: 5 .........Next Book........... Books information Book title : C Book author : RAMBO Book subject : PROGRAMMING Book book_id : 1 Book title : DATABASE Book author : RAMBO Book subject : DATA Book book_id : 2 Book title : JAVA Book author : RAMBO Book subject : PROGRAMMING Book book_id : 3 Book title : SQL Book author : RAMBO Book subject : DATABASE Book book_id : 4 Book title : PHP Book author : RABMBO Book su
Explanation:
None
This Particular section is dedicated to Programs only. If you want learn more about C Programming Language. Then you can visit below links to get more depth on this subject.