//C program to demonstrate use of Structure for storing a Book detains for Library Program.
#include <stdio.h>
#include <string.h>
struct Book{
int book_id;
char book_title[30];
char book_publisher[30];
char book_subject[30];
};
int main( ) {
struct Book myBook; // Declare variable of type Book
//Initialise values to myBook variable
myBook.book_id=101;
printf("Enter Book Title:");
gets(myBook.book_title);
printf("Enter Book Publisher Name:");
gets(myBook.book_publisher);
printf("Enter Book Subject:");
gets(myBook.book_subject);
/* print myBook details */
printf( "Book ID: %d\n", myBook.book_id);
printf( "Book Title: %s\n", myBook.book_title);
printf( "Book Publisher Name : %s\n", myBook.book_publisher);
printf( "Book Subject : %s\n", myBook.book_subject);
return 0;
}
Output of program
Enter Book Title:Computer Studies
Enter Book Publisher Name:ABC India
Enter Book Subject:Computer Science
Book ID: 101
Book Title: Computer Studies
Book Publisher Name : ABC India
Book Subject : Computer Science
#include <string.h>
struct Book{
int book_id;
char book_title[30];
char book_publisher[30];
char book_subject[30];
};
int main( ) {
struct Book myBook; // Declare variable of type Book
//Initialise values to myBook variable
myBook.book_id=101;
printf("Enter Book Title:");
gets(myBook.book_title);
printf("Enter Book Publisher Name:");
gets(myBook.book_publisher);
printf("Enter Book Subject:");
gets(myBook.book_subject);
/* print myBook details */
printf( "Book ID: %d\n", myBook.book_id);
printf( "Book Title: %s\n", myBook.book_title);
printf( "Book Publisher Name : %s\n", myBook.book_publisher);
printf( "Book Subject : %s\n", myBook.book_subject);
return 0;
}
Output of program
Enter Book Title:Computer Studies
Enter Book Publisher Name:ABC India
Enter Book Subject:Computer Science
Book ID: 101
Book Title: Computer Studies
Book Publisher Name : ABC India
Book Subject : Computer Science
No comments:
Post a Comment