#include #include // no la so thuc nen ko dung limts vi limits laf dung cho so nguyen #include double inputCheck(char msg[], char error[], double min, double max){ double num; int check; char c; do{ printf("%s",msg); check=scanf("%lf%c", &num, &c);//Returns the value of an integer fflush(stdin); if(check!=2||c != '\n' || num<=min || num>max){ printf("%s",error); fflush(stdin);//Delete buffer check=0; //input is a character } else{ check=1; //input is a number } }while(check==0); return num; } int main(){ double tienN = inputCheck("No bao nhieu ma?", "Dien lai di ma oi.", 0.0, DBL_MAX); double phanT = inputCheck("Bao nhieu phan tram?", "Dien lai di ma.", 0.0, DBL_MAX); double traT = inputCheck("Moi thang tra bao tien?", "Dien lai di ma.", 0.0, DBL_MAX); phanT=phanT/12; int thang=0; printf("Month\tPayment amount owed\n"); do{ tienN = tienN + tienN*(phanT/100); // goc + lai sau 1 month. if(tienN>traT){ tienN=tienN-traT; }else{ traT=tienN; tienN=0; } thang++; printf("%d\t%0.2lf %0.2lf\n",thang ,traT, tienN); }while(tienN!=0); return 0; }