C Program To create book details using C-Structure
Program:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
struct bookInfo{
char name[25];
char author[25];
int pages;
float price;
};
int main() {
struct bookInfo book;
// Taking book name from user
printf("Enter Name Of Book: ");
fgets(book.name, sizeof(book.name), stdin);
// Taking author name from user
printf("Enter Name Of Book-Author: ");
fgets(book.author, sizeof(book.author), stdin);
// Taking number of total pages of book from user
printf("Enter Number Of Pages in Book: ");
scanf("%d",&book.pages);
// Taking price of book from user
printf("Enter the Price of Book: ");
scanf("%f",&book.price);
// Showing Book Information As Ouutput
printf("\nBook Name is: %s",book.name);
printf("Book-Author Name is: %s",book.author);
printf("Total pages in Book are: %d\n",book.pages);
printf("Price of Book is: %.2f\n",book.price);
return 0;
}
If You Find Difficulty In Reading Above Code Then Try Above Code:
https://cplayground.com/?p=pig-crane-rabbit
Algorithm
1. Start
2. Declare a structure
3. Declare variables in struct
4. Initialize structure inside main
5. Take input from the user and store it in variables declared in the structure
6. Display the information
7. Stop

Comments
Post a Comment