The Program in C to Read info of 20 books,print names, author names of those books whose price is more than 1000 Rs is given below:
#include <stdio.h>
struct Book {
char name[50];
char author[50];
float price;
};
int main() {
int n = 20, i;
struct Book books[20];
// Read info of 20 books
for (i = 0; i < n; i++) {
printf("Enter the name of the book: ");
scanf("%s", books[i].name);
printf("Enter the author of the book: ");
scanf("%s", books[i].author);
printf("Enter the price of the book: ");
scanf("%f", &books[i].price);
}
// Print names and author names of books whose price is more than 1000 Rs
printf("Books whose price is more than 1000 Rs:\n");
for (i = 0; i < n; i++) {
if (books[i].price > 1000) {
printf("%s by %s\n", books[i].name, books[i].author);
}
}
return 0;
}
Output:
Enter the name of the book: Harry Potter
Enter the author of the book: J.K. Rowling
Enter the price of the book: 800
Enter the name of the book: The Lord of the Rings
Enter the author of the book: J.R.R. Tolkien
Enter the price of the book: 1100
Enter the name of the book: The Hobbit
Enter the author of the book: J.R.R. Tolkien
Enter the price of the book: 900
…
Books whose price is more than 1000 Rs:
The Lord of the Rings by J.R.R. Tolkien
Pro-Tips💡
The above code is a simple implementation of a program in C that reads the information of 20 books and prints the names and author names of those books whose price is more than 1000 Rs.
It uses a struct called ‘Book’ to store the information of a single book.
The struct has three members: name, author and price.
The program prompts the user to enter the information of 20 books and stores it in an array of structs called ‘books’.
Then, it iterates through the array and prints the name and author name of books whose price is greater than 1000 Rs
Learn C-Sharp ↗
C-sharp covers every topic to learn about C-Sharp thoroughly.
Learn C Programming ↗
C-Programming covers every topic to learn about C-Sharp thoroughly.
Learn C++ Programming↗
C++ covers every topic to learn about C-Sharp thoroughly.