C Examples

WAP in C to Read info of 20 books,print names, author names of those books whose price is more than 1000 Rs!

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.

Codeauri is Code Learning Hub and Community for every Coder to learn Coding by navigating Structurally from Basic Programming to Front-End Development, Back-End Development to Database, and many more.

Related Posts

C# Program to Find Sum of Rows & Columns of a Matrix

The Program in C# Program to Find Sum of Rows & Columns of a Matrix is given below: Output: Hello Codeauri Family,enter the number of rows and columns…

C# Program to Calculate Determinant of Given Matrix

The Program in C# Program to Calculate Determinant of Given Matrix is given below: Output: Hello Codeauri Family, enter the number of rows and columns of the matrix…

C# Program to Find Sum of right Diagonals of a Matrix

The Program in C# Program to Find Sum of right Diagonals of a Matrix is given below: Output: Hello Codeauri Family, enter the number of rows and columns…

C# Program to Find Transpose of Given Matrix

The Program in C# Program to Find Transpose of Given Matrix is given below: Output: Hello Codeauri Family, enter the number of rows and columns in the matrix:22Enter…

C# Program for Multiplication of two square Matrices

The Program in C# Program for Multiplication of two square Matrices is given below: Output: Hello Codeauri Family, enter the number of rows/columns in the matrices:2Enter the elements…

C# Program to Delete Element at Desired position From Array

The Program in C# Program to Delete Element at Desired position From Array is given below: Output: Hello Codeauri Family, enter the number of elements in the array:4Enter…

Leave a Reply

Your email address will not be published. Required fields are marked *

Your Journey into Code Begins Now: Discover the Wonders of Basic Programming

X