vim simple_and_compound_interest.c
#include <stdio.h>
#include <math.h>
int main()
{
int principal, time;
float rate_of_interest,simple_interest, compound_interest;
printf("Please enter principal, time and rate of interest. ");
scanf("%d%d%f",&principal, &time, &rate_of_interest);
simple_interest = principal * time * rate_of_interest / 100;
printf("Simple interest = %.3f\n", simple_interest);
compound_interest = principal * (pow((1 + rate_of_interest / 100), time) - 1);
printf("Compound interest = %.3f\n", compound_interest);
return 0;
}
test case:
./simple_and_compound_interest
Please enter principal, time and rate of interest. 200 2 3
Simple interest = 12.000
Compound interest = 12.180