使用 C 语言中的公式计算利息金额
问题
编写一个 C 程序,以计算若干年后本金增加利息后的金额
解决方案
计算利息的公式为:
M=((r/100) * t); A=P*exp(M);
其中 r = 利率
t = 年数
P = 要存放的金额
M = 临时变量
A = 有利息后的最终金额
算法
START Step 1: declare double variables Step 2: read amount to be deposited Step 3: read rate of interest Step 4: read years you want to deposit Step 5: Calculate final amount with interest I. M=((r/100) * t); II. A=P*exp(M); Step 6: Print final amount STOP
示例
#include<stdio.h>
#include<math.h>
#include<ctype.h>
int main(){
double P,r,t,A,M;
printf("amount to be deposit in the bank: ");
scanf("%lf",&P);
printf("
enter the rate of interest:");
scanf("%lf",&r);
printf("
How many years you want to deposit:");
scanf("%lf",&t);
M=((r/100) * t);
A=P*exp(M);
printf("
amount after %0.1lf years with interest is:%0.2lf",t,A);
return 0;
}输出
amount to be deposit in the bank: 50000 enter the rate of interest:6.5 How many years you want to deposit:5 amount after 5.0 years with interest is:69201.53
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP