"#include <stdio.h>\n\nint main() {\n double principal = 100000;\n double rate1 = 0.055;\n double rate2 = 0.0475;\n double interest1 = 0;\n double interest2 = 0;\n\n // 利息不计入本金的方式\n for (int i = 0; i < 5; i++) {\n interest1 += principal * rate1;\n }\n double total1 = principal + interest1;\n\n // 利息计入下一年度本金的方式\n for (int i = 0; i < 5; i++) {\n principal += principal * rate2;\n interest2 += principal * rate2;\n }\n double total2 = principal + interest2;\n\n printf("第一种方式的收益为:%.2f\n", total1);\n printf("第二种方式的收益为:%.2f\n", total2);\n\n if (total1 > total2) {\n printf("第一种方式的收益更高。\n");\n } else if (total1 < total2) {\n printf("第二种方式的收益更高。\n");\n } else {\n printf("两种方式的收益相同。\n");\n }\n\n return 0;\n}\n"\n\n以上程序先定义了存款本金、利率和利息的变量,然后使用循环计算每种方式的利息,并累加到本金上。最后,输出两种方式的收益,并比较判断哪种方式的收益更高。\n\n运行程序后,将会输出两种方式的收益,并给出结论。


原文地址: https://www.cveoy.top/t/topic/qwJb 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录