c program to calculate compound interest using function

write a c program to calculate compound interest using function , the user should give input as the principle P, the rate of interest R and time duration T, based upon user input program will calculate compound interest as an output.

Compound interest

it is the addition of interest to the principal sum of a loan or deposit, or we can say that interest on interest.

the formula to find Compound interest

compound interest= P * (1 + R / 100) t

where

P=principal amount

R=Rate of Interest

t=Time duration

The logic to find Compound Interest

  1. ask the user to input principal, the rate of interest and time duration.
  2. store Principal in a variable P
  3. the rate of interest in a variable R
  4. Time duration in a variable T
  5. use formula to find Principle * (1 + Rate / 100) time
  6. print output
Example:-
1.
principal amount:- 5000
time Duration: 2
rate of interest: 5
Compound Interest = 5512.499512

2.

principal amount:- 2000
time Duration: 2
rate of interest: 3
Compound Interest = 2121.799

3.

principal amount:- 15000
time Duration: 2
rate of interest: 5
Compound Interest = 16537.498047

 C program to calculate Compound Interest

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

int main()
{
    float P, R, T, Compound_Interest;
    printf("principal amount:- ");
    scanf("%f", &P);
    printf("time Duration: ");
    scanf("%f", &T);
    printf("rate of interest: ");
    scanf("%f", &R);
    /*compound interest */
    Compound_Interest = P* (pow((1 + R / 100), T));
    printf("Compound Interest = %f",Compound_Interest );
    return 0;
}

C program to calculate Compound Interest using function

#include <stdio.h>
#include <math.h>
float compound(float P,float R,float T);
int main()
{
    float P, R, T, Compound_Interest;
    printf("principal amount:- ");
    scanf("%f", &P);
    printf("time Duration: ");
    scanf("%f", &T);
    printf("rate of interest: ");
    scanf("%f", &R);
    /*compound interest */
    Compound_Interest= compound(P,R,T);
    printf("Compound Interest = %f",Compound_Interest );
    return 0;
}
float compound(float P,float R,float T)
{
	float CI=P* (pow((1 + R / 100), T));
	return CI;
	
}

 

c program to calculate Compound Interest using function

use online IDE to Run and get output Click here


you may also like

C program to calculate simple interest using function

Leave a Reply

Your email address will not be published. Required fields are marked *