#include <stdio.h>
#include <conio.h>
//gọi hàm tính lãi suất ở dưới lên
float tinhlaisuat (int tienvay);
main()
{
int tienvay,namvay;
int tong=0;
float muclaisuat;
float tienlai;
//nhập vào số tiền vay và số năm
printf("Nhap so tien vay: "); scanf("%d",&tienvay);
printf("Nhap so nam vay: "); scanf("%d",&namvay);
//nếu nhỏ hơn 1tr thì không cho vay
if (tienvay<1000000)
{
printf("Khong cho vay");
}
//ngược lại, nếu lớn hơn 1tr thì cho vay, khi đó dùng hàm đã tạo ở trên để tính mức lãi suất
else
{
muclaisuat=tinhlaisuat(tienvay);
tienlai=muclaisuat*tienvay*namvay;
tong=tienvay+tienlai;
//đưa kết quả ra màn hình
printf("\nTien vay: %d",tienvay);
printf("\nSo nam vay: %d",namvay);
printf("\nMuc lai suat: %.3f",muclaisuat);
printf("\nTien lai phai tra: %.3f",tienlai);
printf("\nTong phai tra: %d",tong);
}
getch();
}
//tạo hàm tính lãi suất
float tinhlaisuat (int tienvay)
{
float laisuat;
if (tienvay<1000000)
{
printf("Khong cho vay");
}
else if (tienvay<5000000)
{
laisuat=0.1;
}
else if (tienvay<10000000)
{
laisuat=0.095;
} else if (tienvay<50000000)
{
laisuat=0.09;
}
else if (tienvay<100000000)
{
laisuat=0.085;
}
else laisuat=0.08;
return laisuat;
}
Thứ Năm, 11 tháng 4, 2019
[C] Tạo hàm tính lãi suất vay
Đăng ký:
Đăng Nhận xét (Atom)
Không có nhận xét nào:
Đăng nhận xét