C PROGRAMMING PROGRAM • BASICS & INPUT/OUTPUT
Calculate Compound Interest
Learn how to calculate compound interest using a clear C program.
PROBLEM UNDERSTANDING
Input and expected output
Sample input
10000 10 2
Sample output
Compound interest = 2100.00 Total amount = 12100.00
COMPLETE C PROGRAM
Complete C implementation
#include <stdio.h>
#include <math.h>
int main(void)
{
double principal, rate, time, amount;
printf("Enter principal, annual rate and time: ");
scanf("%lf %lf %lf", &principal, &rate, &time);
amount = principal * pow(1.0 + rate / 100.0, time);
printf("Compound interest = %.2f\n", amount - principal);
printf("Total amount = %.2f\n", amount);
return 0;
}CURRENT STEP
SELECTED LINE
EXPECTED OUTPUT FOR THE SAMPLE
Compound interest = 2100.00 Total amount = 12100.00
Step 0 of 0
PROGRAM EXPLANATION
Algorithm and explanation
- Read the required input values.
- Compute P(1+R/100)^T using pow(), then subtract the principal.
- Display the computed result.
Compute P(1+R/100)^T using pow(), then subtract the principal.
EFFICIENCY
Time and space complexity
Time complexity
O(1)
Auxiliary space
O(1)
DEBUGGING CHECKLIST
Common mistakes
Check this
Use the correct format specifier for every variable.
Check this
Initialize variables before using their values.
Check this
Check braces, semicolons and input order carefully.
Try it yourself
Practice: Run the program with the sample input, predict its output, and then test one boundary case of your own.
