gpt4 book ai didi

C 复利季刊

转载 作者:行者123 更新时间:2023-11-30 17:25:34 25 4
gpt4 key购买 nike

我在这段代码中遇到一个问题:输出结果始终与主体具有相同的值。为什么?

#include <math.h>
#include <conio.h>

void main()
{
float principal, rate, total_amount, interest, i, j;
int time, year, quarterly, x, y;

printf("Enter Principal : ");
scanf("%f", &principal);
printf("Enter Interest Rate : ");
scanf("%f", &rate);
printf("Enter Time : ");
scanf("%d", &time);

for(x = 1; x <= time; x++)
{
i = rate / 400;
total_amount = principal * pow(1 + (i), x); //total_amount = total_end
interest = total_amount - principal;

printf("%d\t\t %.2f\t\t %.2f\t\t %.2f\n", x, principal, interest, total_amount);
}

getch();
}

最佳答案

我不确定我是否正确理解了您的单行问题陈述,但在我看来,您没有更新下一次迭代的主体。

你应该使用

for(x = 1; x <= time; x++)
{
i = rate / 400;
total_amount = principal * pow(1 + (i), x); //total_amount = total_end
interest = total_amount - principal;

printf("%d\t\t %.2f\t\t %.2f\t\t %.2f\n", x, principal, interest, total_amount);
principal = total_amount ; //see here
}

关于C 复利季刊,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27032730/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com