【经典C程序】计算单利和复利

【经典C程序】计算单利和复利_第1张图片

vim simple_and_compound_interest.c

#include 
#include 

int main()
{
        int principal, time;
        float rate_of_interest,simple_interest, compound_interest;
        printf("Please enter principal, time and rate of interest. ");

        scanf("%d%d%f",&principal, &time, &rate_of_interest);

        simple_interest = principal * time * rate_of_interest / 100;
        printf("Simple interest = %.3f\n", simple_interest);

        compound_interest = principal * (pow((1 + rate_of_interest / 100), time) - 1);
        printf("Compound interest = %.3f\n", compound_interest);

        return 0;
}

test case:

【经典C程序】计算单利和复利_第2张图片
./simple_and_compound_interest
Please enter principal, time and rate of interest. 200 2 3
Simple interest = 12.000
Compound interest = 12.180

你可能感兴趣的:(经典C程序,c语言)