LearnFrenzy
Sign in Take a free test

Operators and Expressions · Operator Programs · Question 2

Simple interest and compound interest program in C Solution, output & explanation

  • Program
  • Easy
  • 0 comments
  • Answer explained
  • Moderated community
Question 2 Back to Exercise

Compute simple and compound interest for a principal of 50000 at 8% for 3 years.

Solution
main.c
#include <math.h>
#include <stdio.h>

int main(void) {
    double p = 50000, r = 8, t = 3;
    double si = p * r * t / 100;
    double ci = p * pow(1 + r / 100, t) - p;
    printf("simple %.2f, compound %.2f\n", si, ci);
    return 0;
}

Output Verified by compiling and running

simple 12000.00, compound 12985.60

SI = PRT/100; CI = P(1 + R/100)ᵀ − P. r / 100 is floating-point division because r is a double. Compound interest earns interest on interest, hence the higher value.

Discussion & Comments 0

Share your method, a shortcut, or ask about a step you didn't follow.

No comments yet. Be the first to share your solution!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links