|
发表于 2024-4-21 00:07:20
|
显示全部楼层
小凡,下面是用C语言编写的程序:
- #include <stdio.h>
- float calculateGDP(float r, int years);
- float calculateInterest(int type, int years);
- int main() {
- // 计算国民生产总值与现东中比增长多少百分比
- float gdp_growth_rate = 0.07; // 国民生产总值年增长率为7%
- int gdp_years = 10; // 年数为10年
- float gdp_ratio = calculateGDP(gdp_growth_rate, gdp_years);
- printf("国民生产总值与现东中比增长了 %.2f%%\n", (gdp_ratio - 1) * 100);
- // 存款利息的计算
- float interest1 = calculateInterest(1, 5); // 方案1
- float interest2 = calculateInterest(2, 2) + calculateInterest(1, 3); // 方案2
- float interest3 = calculateInterest(3, 3) + calculateInterest(2, 2); // 方案3
- float interest4 = 1; // 方案4
- for (int i = 0; i < 5; i++) {
- interest4 *= calculateInterest(1, 1);
- }
- float interest5 = calculateInterest(0, 5); // 方案5
- printf("方案1:一次存5年期,本息和为 %.2f\n", interest1);
- printf("方案2:先存2年期,到期后再存3年期,本息和为 %.2f\n", interest2);
- printf("方案3:先存3年期,到期后再存2年期,本息和为 %.2f\n", interest3);
- printf("方案4:存1年期,到期后再存1年期,连续存5次,本息和为 %.2f\n", interest4);
- printf("方案5:存活期存款,本息和为 %.2f\n", interest5);
- return 0;
- }
- // 计算国民生产总值与现东中比增长的倍数
- float calculateGDP(float r, int years) {
- float p = 1;
- for (int i = 0; i < years; i++) {
- p *= (1 + r); // 计算与现在相比的倍数
- }
- return p;
- }
- // 计算存款本息和
- float calculateInterest(int type, int years) {
- float interest_rate;
- if (type == 1) {
- interest_rate = 0.015; // 1年期定期存款利息为 1.5%
- } else if (type == 2) {
- interest_rate = 0.021; // 2年期定期存款利息为 2.1%
- } else if (type == 3) {
- interest_rate = 0.0275; // 3年期定期存款利息为 2.75%
- } else if (type == 5) {
- interest_rate = 0.03; // 5年期定期存款利息为 3%
- } else {
- interest_rate = 0.0035; // 活期存款利息为 0.35%
- }
- float p = 1000;
- for (int i = 0; i < years; i++) {
- p *= (1 + interest_rate); // 计算本息和
- }
- return p;
- }
复制代码
希望能帮到你!如果还有其他问题,请随时提问。
以上回复来自 FishC AI 小助理,如未能正确解答您的问题,请继续追问。 |
|