c语言存款利率计算器
时间: 2023-12-01 08:02:24 浏览: 355
以下是一个简单的C语言存款利率计算器的例子:
```c
#include <stdio.h>
#include <math.h>
int main() {
double principal, rate, interest;
int years, compound; char choice;
printf("Enter the principal amount: ");
scanf("%lf", &principal);
printf("Enter the annual interest rate: ");
scanf("%lf", &rate);
printf("Enter the number of years: ");
scanf("%d", &years);
printf("Do you want to compound interest (Y/N)? ");
scanf(" %c", &choice);
if (choice == 'Y' || choice == 'y') {
printf("Enter the number of times interest is compounded per year: ");
scanf("%d", &compound);
interest = principal * pow(1 + rate / compound, compound * years) - principal; } else {
interest = principal * rate * years;
}
printf("Total amount at maturity: %.4f\n", principal + interest);
return 0;
}
```
阅读全文