Question #23618

how to program compound interest using only p,r,t,and n(no.of times compounded each year?NO use of math.h just stdio.h.

Expert's answer

#include <stdio.h>int main(){

floatp = 0, r = 0;

intt = 0, n = 0;

printf("Enterprincipal amount (initial investment): ");

scanf("%f",&p);

printf("Enterannual nominal interest rate (as a decimal, not in percentage): ");

scanf("%f",&r);

printf("Enternumber of years: ");

scanf("%d",&t);

printf("Enternumber of times the interest is compounded per year: ");

scanf("%d",&n);

for(inti = 0; i < t*n; i++){

p+= p*r/n;

}

printf("

Thebalance after %d year(s): %f

", t, p);

return0;

}

floatp = 0, r = 0;

intt = 0, n = 0;

printf("Enterprincipal amount (initial investment): ");

scanf("%f",&p);

printf("Enterannual nominal interest rate (as a decimal, not in percentage): ");

scanf("%f",&r);

printf("Enternumber of years: ");

scanf("%d",&t);

printf("Enternumber of times the interest is compounded per year: ");

scanf("%d",&n);

for(inti = 0; i < t*n; i++){

p+= p*r/n;

}

printf("

Thebalance after %d year(s): %f

", t, p);

return0;

}

## Comments

## Leave a comment