Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
1.2 kB
4
Indexable
Never
#include<stdio.h>
typedef struct Hang
{
    int ISBN,soLuong;
    float gia, giaTri;
}h;
void nhap(h a[], int n)
{
    for(int i = 0; i < n;i++)
    {    
     printf("Nhap mat hang thu %d: ", i+1);
     scanf("%d", &a[i].ISBN);   
     scanf("%f", &a[i].gia);
     scanf("%d", &a[i].soLuong);
     a[i].giaTri = a[i].gia * (float)a[i].soLuong;
    }
}
void inTieuDe()
{
     printf("\n\t\t\tBooks in Stock");
     printf("\n\t\t\t==============\n");
     printf("%-20s %-20s %-20s %-20s", "ISBN", "Price", "Quantity" , "Value");
     printf("\n----------------------------------------------------------------------\n");
}
void in(h a[], int n)
{
      float sum = 0;
      for(int i = 0 ; i < n ; i++)
      {
          printf("\n%-20d %-20.2f %-20d %-20.2f", a[i].ISBN , a[i].gia, a[i].soLuong, a[i].giaTri);
          sum+= a[i].giaTri;
      }
      printf("\nTotal value books in stock: %.2f", sum);
} 
int main()
{
    int soMatHang;
    printf("Nhap so luong mat hang: ");
    scanf("%d", &soMatHang);
    h a[100];
    printf("\nNhap mat hang ( ISBN - gia - soLuong):\n");
    nhap(a,soMatHang);
    inTieuDe();
    in(a,soMatHang);
    return 0;
}