等差数列和等比数列(快速求存储年份)

1.找规律。
2.把所有的项都与第一项对比(总结出公式)
3.把具体要计算的项代入。

 

 知道本金、利息,和目标金额,求出大概多少年后,可以完成该目标。

 1 #include<stdio.h>
 2 #include<stdlib.h>
 3 #include<math.h>
 4 int main() {
 5 float l_Principal = 100; //初始化本金
 6 float l_Interest = 0.067; //初始化年利息
 7 float l_Target = 1000; //目标金额
 8 
 9 //根据本金、利息,求出多少年以后,会得到目标金额。
10 int l_Years = log(l_Target / l_Principal) / log(l_Interest + 1);
11 printf("大概第:[%d]年,目标金额达到[%f]
", l_Years + 2, l_Target);
12 system("pause");
原文地址:https://www.cnblogs.com/jikebiancheng/p/12202659.html