Answer: Amount \( A = P\left(1 + \frac{R}{100}\right)^{T} \) and compound interest \( CI = A - P \).
Correction: time is a float, so it must be printed with %f (here %.0f), not %d. Passing a float to %d gives garbage output.
Program:
/* C program to calculate compound interest */
#include <stdio.h>
#include <math.h>
int main()
{
float principal, rate, time, amount, interest;
printf("Enter principal: ");
scanf("%f", &principal);
printf("Enter rate of interest (%% per year): ");
scanf("%f", &rate);
printf("Enter time (years): ");
scanf("%f", &time);
amount = principal * pow(1 + rate / 100, time);
interest = amount - principal;
printf("After %.0f years\n", time);
printf("Total amount = %.2f\n", amount);
printf("Compound interest = %.2f\n", interest);
return 0;
}Sample output (actual run):
Enter principal: 10000
Enter rate of interest (% per year): 8
Enter time (years): 2
After 2 years
Total amount = 11664.00
Compound interest = 1664.00Check: \( 10000 \times 1.08^2 = 11664 \), so CI = 1664. Compile with gcc ci.c -lm (the -lm links the maths library for pow).