C Program to Calculate Compound Amount

C Program to Calculate Compound Amount

Formula to find the compound amount

Compound interest formula

Where, 

P = principle

R = rate

T = time

 C program to print compound amount

Here in the program, 
Value of principle is store in variable p
Value of rate is store in variable r
Value of time is store in variable t

#include<stdio.h>

#include<conio.h>

#include<math.h>

void main()

{

          float p, r, t, ca, a, b, c;

           // taking value of principle, rate and interest from the user

          printf("\n Enter the value of principle, rate and time");

          scanf("%f%f%f", &p, &r, &t);

          a=r/100; //performing rate/100

          b=1+a; // performing (1+r/100)

          c=pow(b,t); // performing (1+r/100)t

          ca=p*c; // performing p*(1+r/100)t

          printf("\n Compound Amount is %f", ca);

          getch();

}

Output

Compound interest in C



C program to calculate compound amount without using pow()

#include<stdio.h>

#include<conio.h>

void main()

{

          float p, t, r, i, z=1, ca, a, b;

          // taking input from the user

          printf("\n Enter the value of principle, rate and time");

          scanf("%f%f%f", &p, &t, &r);

          a = r/100; // performing r/100

          b = (1+a); // performing (1+r/100)

          for(i=1;i<=t;i++)

          {

                   // to perform (1+r/100)

                   z=z*b; // b is varible where value of (1+r/100) stored

          }

          ca = p*z; // value of (1+r/100) store in z

          printf("\n Compound Amount is %f", ca);

          getch();

}

Output

Compound amount without pow() in C


C program to calculate compound amount using function

#include<stdio.h>

#include<conio.h>

#include<math.h>

void ci(float,float,float); // function prototype

int main()

{

          float p, r, t;

          // taking value of principle, rate and interest from the user

          printf("\n Enter the value of principle, rate and time");

          scanf("%f%f%f", &p, &r, &t);

          ci(p,r,t); // function call

          getch();

}

void ci(float p, float r, float t)

{

          float a, b, c, ca;

          a=r/100; //performing rate/100

          b=1+a; // performing (1+r/100)

          c=pow(b,t); // performing (1+r/100)t

          ca=p*c; // performing p*(1+r/100)t

          printf("\n Compound Amount is %f", ca);

          getch();

}

Output

Compound amount in C using function







Post a Comment

0 Comments