void power(float P,float R,float n,float A);
void main()
{
float A,P,R,n;
clrscr();
printf("Enter principal amount:");
scanf("%f",&A);
printf("Enter rate of interest:");
scanf("%f",&R);
printf("Enter number of years:");
scanf("%f",&n);
power(A,R,P,n);
getch();
}
void power(float A,float R,float P,float n)
{
int i;
for(i=1;i<=n;i++)
{
A=1+(R*0.01);
A=A*i;
A=A*P;
printf("For year %d, C.I =%f\n",i,A);
}
}
I put
Principal = 2000
Rate of interest=3
Years=3
我将复利的价值变为负值。错误在A = A * P;必须在不使用幂函数的情况下计算每年的复利
答案 0 :(得分:0)
#include<stdio.h>
void power(float P,float R,float n,float A);
void main()
{
float A,P,R,n;
// clrscr();
printf("Enter principal amount:");
scanf("%f",&A);
printf("Enter rate of interest:");
scanf("%f",&R);
printf("Enter number of years:");
scanf("%f",&n);
power(A,R,P,n);
// getch();
}
void power(float A,float R,float P,float n)
{
int i;
float intr=0;
for(i=1;i<=n;i++)
{
intr=0;
intr=A*(R/100);
A=A+intr;
// A=A*P;
printf("For year %d, C.I =%f\n",i,intr);
}
}