#include<conio.h> #include<stdlib.h> #include<stdio.h> #include<math.h> #include<string.h> struct hanghoa { char tenhang[30]; float dg; int soluong; float tien; }; int main() { hanghoa hh[200]; int n,i;float tien; printf("nhap so luong hang hoa :"); scanf("%d",&n); printf("nhap thong tin cho tung loai hang \n"); for(i=0;i<n;i++) { printf("nhap loai hang thu %d",i+1); printf("\nnhap ten mat hang : "); fflush(stdin); gets(hh[i].tenhang); printf("\nnhap so luong : "); fflush(stdin); scanf("%d",&hh[i].soluong); printf("\nnhap don gia : "); fflush(stdin); scanf("%f",&hh[i].dg); hh[i].tien=hh[i].soluong*hh[i].dg ; } printf("hoa don sau khi nhap la "); i=1; printf("\nSTT loai hang so luong don gia thanh tien\n"); for(i=0;i<n;i++) { printf("%d",i+1); printf("%15s ",hh[i].tenhang); printf("%15d",hh[i].soluong); printf("%20.0f",hh[i].dg); printf("%22.0f",hh[i].tien); printf("\n"); } float tong=0; printf("\n tong so tien la :"); for(i=0;i<n;i++) tong+=hh[i].tien; printf("%.0f\n",tong); getch(); }
Tags:
lập trình c