Sunday, 24 April 2022

2. Write a program to create a list of books details. The details of a book include title, author, publisher, publishing year, number of pages, and price.

 



#include<stdio.h>
#include<conio.h>

struct book
{
    char t[20],a[20],p[20];
    int py,pg,pr;
}b[5];

void main()
{
    int no,i;
    clrscr();
    printf("how many number of books: ");
    scanf("%d",&no);

    if(no>5)
    {
        printf("\n\nenter less than 5");
    }
    else
    {
        for(i=0; i<no; i++)
        {
            printf("!! enter %d book title !!",i+1);
            scanf("%s",b[i].t);
            printf("enter %d book author name: ",i+1);
            scanf("%s",b[i].a);
            printf("enter %d book publisher name: ",i+1);
            scanf("%s",b[i].p);
            printf("enter %d book publisher year: ",i+1);
            scanf("%d",&b[i].py);
            printf("enter %d book number of pages: ",i+1);
            scanf("%d",&b[i].pg);
            printf("enter %d book price: ",i+1);
            scanf("%d",&b[i].pr);

            printf("\n\n");
        }

        printf("\n\nenterd data :\n");
        for(i=0; i<no; i++)
        {
            printf("enter %d book title: %s",i+1,b[i].t);
            printf("\nenter %d book author name: %s",i+1,b[i].a);
            printf("\nenter %d book publisher name: %s",i+1,b[i].p);
            printf("\nenter %d book publisher year: %d",i+1,b[i].py);
            printf("\nenter %d book number of pages: %d",i+1,b[i].pg);
            printf("\nenter %d book price: %d",i+1,b[i].pr);
            printf("\n\n");
        }
    }
    getch();
}

/*  output:

how many number of books: 1
enter 1 book title: rema
enter 1 book author name: thareja
enter 1 book publisher name: pub
enter 1 book publisher year: 2014
enter 1 book number of pages: 300
enter 1 book price: 500




!! enterd data !!
enter 1 book title: rema
enter 1 book author name: thareja
enter 1 book publisher name: pub
enter 1 book publisher year: 2014
enter 1 book number of pages: 300
enter 1 book price: 500

*/

No comments:

Post a Comment

python programs

1. sum of two number