If the amount deposited in a bank (i.e., principal), number of years and interest rate are denoted asp, n and r, respectively, compound interest (compounded annually) as p(1+r/100)n. The program segment given below calculates and prints compound interest on deposit.
The scanf statement reads the amount deposited (p of type float),interest rate (r of type float),number of years (n of type float)
#include <stdio.h>
#include <math.h>
void main( )
{
float p, r, n, i,f;
clrscr();
printf("P1ease enter a value for the prinipal (P) : " ) ;
scanf ( "%f", &p);
printf("P1ease enter a value for the interestrate ( r ) : " ) ;
scanf ("%f" , & r );
printf("P1ease enter a value for the number of years (n) : " ) ;
scanf ( " % f ", n) ; /* calculate i,then f */
i= r/100;
f = p * pow((1 + i ) , n ) ;
printf ( "\nThe final value (F) is : %.2f\n", f ) ;
getch();
}