fork(3) download
  1. #include <stdio.h>
  2. #include <math.h> // Required for pow()
  3.  
  4. // Function prototypes
  5. float Calculate_Simple_Interest(float principle, float rate, float time);
  6. float Calculate_Compound_Interest(float principle, float rate, float time);
  7.  
  8. // Function to calculate simple interest
  9. float Calculate_Simple_Interest(float principle, float rate, float time)
  10. {
  11. float interest;
  12. interest = principle * rate * time;
  13. return interest;
  14. }
  15.  
  16. // Function to calculate compound interest
  17. float Calculate_Compound_Interest(float principle, float rate, float time)
  18. {
  19. float interest;
  20. interest = (principle * pow(1.0 + rate, time)) - principle;
  21. return interest;
  22. }
  23.  
  24. int main(void)
  25. {
  26. float principle, rate, time;
  27. float interest, interest_compound;
  28.  
  29. printf("\nEnter your principle value: ");
  30. scanf("%f", &principle);
  31.  
  32. printf("\nEnter the rate (e.g. 0.095 for 9.5 percent): ");
  33. scanf("%f", &rate);
  34.  
  35. printf("\nEnter the time in years: ");
  36. scanf("%f", &time);
  37.  
  38. interest = Calculate_Simple_Interest(principle, rate, time);
  39. interest_compound = Calculate_Compound_Interest(principle, rate, time);
  40.  
  41. printf("\nThe total simple interest earned is: $%.2f\n", interest);
  42. printf("The total compound interest earned is: $%.2f\n", interest_compound);
  43.  
  44. return 0;
  45. }
Success #stdin #stdout 0s 5284KB
stdin
4500
0.095
6
stdout
Enter your principle value: 
Enter the rate (e.g. 0.095 for 9.5 percent): 
Enter the time in years: 
The total simple interest earned is: $2565.00
The total compound interest earned is: $3257.06