Pages

Thursday, January 23, 2025

Calculate Compound interest in C Language

#include<stdio.h>
#include<math.h>

int main() {
float CompoundInterest, rate, time, principal, n, amount;

/*

1. Take Input from User
principal amount, rate(%), n(per yr), time(in yrs)

n = no. of times interest compounded per year

*/

rate = rate /100;

amount = principal * pow((1+r/n), n*time);

CompoundInterest = amount-principal;


/*

2. Display the Result

printf("The Total Amount: %.2f\n", amount);

printf("The Compound Interest %.2f\n", CompoundInterest);

*/


return 0;

}


CODE TESTED and RAN!

Update:-
- Reduced complexity, confusion.
- Made it understandable & readable.

Mistakes:- 
- don't forget to put comma "," after pow here's an example:-
principal * pow(1+r/n),n*time);

No comments:

Post a Comment

how to become red on codeforces by Errichto Algorithms | explained simply in a blog

 Yes. I found an available transcript of the video and summarized it simply. The video is “How To Become Red Coder? (codeforces.com)” by Err...