Travel with cheap hotels and flights ! Book online now

Travel with cheap hotels and flights ! Book online now
Travel with cheap hotels and flights ! Book online now

Thursday, 2 February 2017

Write a program in c language to input the details of 3 books ( name, price, quantity) and then calculate its total cost.

Write a program in c language to input the details of 3 books ( name, price, quantity) and then calculate its total cost.

#include<stdio.h>
#include<conio.h>
void main()
{
       struct book                // structure book
       {
            char bname[20];
            int p,qty,tc ;                 // p is price ; qty is quantity, tc is total cost
         };

                struct book b1, b2, b3;    // b1 is book 1, b2 is book 2, b3 is book 3
                clrscr();
                printf(" Enter details of book 1");
                printf("\n Bookname");
                scanf("%s", b1.bname);   // enter name of book
                printf(" Enter price & qty");
                scanf("%d%d",&b1.p,&b1.qty); // enter the price and quanity of book 1

               printf(" Enter details of book 2");
                printf("\n Bookname");
                scanf("%s", b2.bnaame);
                printf(" Enter price & quty");
                scanf("%d%d",&b2.p,&b2.qty); // enter the price and quanity of book 2

               printf(" Enter details of book 3");
                printf("\n Bookname");
                scanf("%s", b3.bnaame);
                printf(" Enter price & quty");
                scanf("%d%d",&b3.p,&b3.qty); // enter the price and quanity of book 3

                b1.tc = b1.p * b1.qty;    // formula to calculate total cost of book1
                b2.tc = b2.p * b1.qty;    // formula to calculate total cost of book2
                b3.tc = b3.p * b1.qty;    // formula to calculate total cost of book3

              printf("Total cost of book1 = %d\n, b1.tc);
              printf("Total cost of book2 = %d\n, b2.tc);
              printf("Total cost of book3 = %d\n, b1.tc);
             
               getch();
}



No comments:

Post a Comment