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 with loop.

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

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

            struct book b[100] ; 
           int i,n ; // i for looping, n is number to enter for books quanity
           clrscr();
           printf("Enter Number of Books");
           scanf("%d",&n);
            
            for(i=0;i<=n-1;n++)  // i starts from first number ie..0, i will be equal to last number ie n-1,                                                                                     //increase one by one
             {
                printf("Enter details of books  %d", i+1);
                printf(" Enter Bookname");
                scanf("%s",&b[i].p, b[i].qty); 
               printf("Enter price and quantity");
               scanf("%d%d",&b[i].p,&b[i].qty);
        
              }
                   for(i=0;i<=n-1;i++)
                   {
                         b[i]tc = b[i].p * b[i].qty;
                           printf(" Total cost of book = %d\n", i+1,b[i].tc);
                     }
                     getch();
}

No comments:

Post a Comment