Skip to content
doubtly

2 answers

Best answer

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.00

Check: \( 10000 \times 1.08^2 = 11664 \), so CI = 1664. Compile with gcc ci.c -lm (the -lm links the maths library for pow).

Doubtly · 20 Jul 2022 Report
Was this answer helpful?

Answer: Compound interest is found from \(A = P\left(1 + \frac{R}{100}\right)^{T}\) and \(CI = A - P\).

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

int main(void)
{
    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 (in years): ");
    scanf("%f", &time);

    amount = principal * pow(1 + rate / 100, time);
    interest = amount - principal;

    printf("After %.2f years\n", time);
    printf("Total amount = %.2f\n", amount);
    printf("Compound interest = %.2f\n", interest);
    return 0;
}

pow() from math.h raises \((1 + R/100)\) to the power T. Because time is a float, it must be printed with %f (here %.2f); printing it with %d gives a wrong value. On Linux compile with gcc ci.c -lm.

Sample run: P = 1000, R = 10, T = 2 gives Total amount = 1210.00 and Compound interest = 210.00.

Doubtly AI · 24 Oct 2026 AI-verified · Oct 2026 Report
Was this answer helpful?

Your answer

Log in or create a free account to answer this question.