fork download
  1. #include <stdio.h>
  2.  
  3. int main(void) {
  4. #include <stdio.h>
  5. #include <math.h> // Required for pow() in CI calculation
  6.  
  7. int main() {
  8.  
  9. // Variable declarations
  10. float principal, rate, time;
  11. float simpleInterest, compoundInterest, amount;
  12.  
  13. // Taking input values
  14. printf("Enter Principal Amount: ");
  15. scanf("%f", &principal);
  16.  
  17. printf("Enter Rate of Interest (per year): ");
  18. scanf("%f", &rate);
  19.  
  20. printf("Enter Time (in years): ");
  21. scanf("%f", &time);
  22.  
  23. /*
  24.   Simple Interest Formula:
  25.   SI = (P * R * T) / 100
  26.   */
  27. simpleInterest = (principal * rate * time) / 100;
  28.  
  29. /*
  30.   Compound Interest Formula:
  31.   Amount = P * (1 + R/100)^T
  32.   CI = Amount - Principal
  33.   */
  34. amount = principal * pow((1 + rate / 100), time);
  35. compoundInterest = amount - principal;
  36. printf("\n----- Interest Calculations -----\n");
  37. printf("Simple Interest = %.2f\n", simpleInterest);
  38. printf("Compound Interest = %.2f\n", compoundInterest);
  39.  
  40. return 0;
  41. }
  42. // your code goes here
  43. return 0;
  44. }
  45.  
Success #stdin #stdout 0.01s 5320KB
stdin
Standard input is empty
stdout
Standard output is empty