# Calculate compound interest

Here given code implementation process.

```
//C Program
//Calculate compound interest
#include <stdio.h>
#include <math.h>
//Method which is take three parameters
//And calculates that compound interest
//Here time is form in year
//rate is form of annual interest rate
void compound_interest(double principle, double time, double rate)
{
//Display parameters values
printf("Principle : %lf\n", principle);
printf("Time : %lf\n", time);
printf("Rate : %lf\n", rate);
//Calculate interest
double amount = principle * (pow((1 + rate / 100), time));
//Display amount
printf("Compound Interest : %lf\n\n", amount);
}
int main()
{
//Test Cases
//Send principle,time and rate
compound_interest(1500, 3, 7.3);
compound_interest(170.4, 7, 3.4);
return 0;
}
```

#### Output

```
Principle : 1500.000000
Time : 3.000000
Rate : 7.300000
Compound Interest : 1853.064025
Principle : 170.400000
Time : 7.000000
Rate : 3.400000
Compound Interest : 215.334374
```

```
/*
Java Program
Calculate compound interest
*/
class MyMaths
{
//Method which is take three parameters
//And calculates that compound interest
//Here time is form in year
//rate is form of annual interest rate
public void compound_interest(double principle, double time, double rate)
{
//Display parameters values
System.out.print("Principle : " + principle + "\n");
System.out.print("Time : " + time + "\n");
System.out.print("Rate : " + rate + "\n");
//Calculate interest
double amount = principle * (Math.pow((1 + rate / 100), time));
//Display amount
System.out.print("Compound Interest : " + amount + "\n\n");
}
public static void main(String[] args)
{
MyMaths obj = new MyMaths();
//Test Cases
//Send principle,time and rate
obj.compound_interest(1500, 3, 7.3);
obj.compound_interest(170.4, 7, 3.4);
}
}
```

#### Output

```
Principle : 1500.0
Time : 3.0
Rate : 7.3
Compound Interest : 1853.0640254999998
Principle : 170.4
Time : 7.0
Rate : 3.4
Compound Interest : 215.334373801618
```

```
/*
C++ Program
Calculate compound interest
*/
#include<iostream>
#include<math.h>
using namespace std;
class MyMaths
{
public:
//Method which is take three parameters
//And calculates that compound interest
//Here time is form in year
//rate is form of annual interest rate
void compound_interest(double principle, double time, double rate)
{
cout << "Principle : " << principle << "\n";
cout << "Time : " << time << "\n";
cout << "Rate : " << rate << "\n";
//Calculate interest
double amount = principle * (pow((1 + rate / 100), time));
cout << "Compound Interest : " << amount << "\n\n";
}
};
int main()
{
MyMaths obj ;
//Test Cases
//Send principle,time and rate
obj.compound_interest(1500, 3, 7.3);
obj.compound_interest(170.4, 7, 3.4);
return 0;
}
```

#### Output

```
Principle : 1500
Time : 3
Rate : 7.3
Compound Interest : 1853.06
Principle : 170.4
Time : 7
Rate : 3.4
Compound Interest : 215.334
```

```
/*
C# Program
Calculate compound interest
*/
using System;
class MyMaths
{
//Method which is take three parameters
//And calculates that compound interest
//Here time is form in year
//rate is form of annual interest rate
public void compound_interest(double principle, double time, double rate)
{
Console.Write("Principle : " + principle + "\n");
Console.Write("Time : " + time + "\n");
Console.Write("Rate : " + rate + "\n");
//Calculate interest
double amount = principle * (Math.Pow((1 + rate / 100), time));
Console.Write("Compound Interest : " + amount + "\n\n");
}
public static void Main(String[] args)
{
MyMaths obj = new MyMaths();
//Test Cases
//Send principle,time and rate
obj.compound_interest(1500, 3, 7.3);
obj.compound_interest(170.4, 7, 3.4);
}
}
```

#### Output

```
Principle : 1500
Time : 3
Rate : 7.3
Compound Interest : 1853.0640255
Principle : 170.4
Time : 7
Rate : 3.4
Compound Interest : 215.334373801618
```

```
<?php
/*
Php Program
Calculate compound interest
*/
class MyMaths
{
//Method which is take three parameters
//And calculates that compound interest
//Here time is form in year
//rate is form of annual interest rate
function compound_interest($principle, $time, $rate)
{
echo "Principle : ". $principle ."\n";
echo "Time : ". $time ."\n";
echo "Rate : ". $rate ."\n";
//Calculate interest
$amount = $principle * (pow((1 + $rate / 100), $time));
echo "Compound Interest : ". $amount ."\n\n";
}
}
function main()
{
$obj = new MyMaths();
//Test Cases
//Send principle,time and rate
$obj->compound_interest(1500, 3, 7.3);
$obj->compound_interest(170.4, 7, 3.4);
}
main();
```

#### Output

```
Principle : 1500
Time : 3
Rate : 7.3
Compound Interest : 1853.0640255
Principle : 170.4
Time : 7
Rate : 3.4
Compound Interest : 215.33437380162
```

```
/*
Node Js Program
Calculate compound interest
*/
class MyMaths
{
//Method which is take three parameters
//And calculates that compound interest
//Here time is form in year
//rate is form of annual interest rate
compound_interest(principle, time, rate)
{
process.stdout.write("Principle : " + principle + "\n");
process.stdout.write("Time : " + time + "\n");
process.stdout.write("Rate : " + rate + "\n");
//Calculate interest
var amount = principle * (Math.pow((1 + rate / 100), time));
process.stdout.write("Compound Interest : " + amount + "\n\n");
}
}
function main()
{
var obj = new MyMaths();
//Test Cases
//Send principle,time and rate
obj.compound_interest(1500, 3, 7.3);
obj.compound_interest(170.4, 7, 3.4);
}
main();
```

#### Output

```
Principle : 1500
Time : 3
Rate : 7.3
Compound Interest : 1853.0640254999994
Principle : 170.4
Time : 7
Rate : 3.4
Compound Interest : 215.33437380161791
```

```
# Python 3 Program
# Calculate compound interest
import math
class MyMaths :
# Method which is take three parameters
# And calculates that compound interest
# Here time is form in year
# rate is form of annual interest rate
def compound_interest(self, principle, time, rate) :
print("Principle : ", principle ,"\n", end = "")
print("Time : ", time ,"\n", end = "")
print("Rate : ", rate ,"\n", end = "")
# Calculate interest
amount = principle * (math.pow((1 + rate / 100), time))
print("Compound Interest : ", amount ,"\n\n", end = "")
def main() :
obj = MyMaths()
# Test Cases
# Send principle,time and rate
obj.compound_interest(1500, 3, 7.3)
obj.compound_interest(170.4, 7, 3.4)
if __name__ == "__main__": main()
```

#### Output

```
Principle : 1500
Time : 3
Rate : 7.3
Compound Interest : 1853.0640254999998
Principle : 170.4
Time : 7
Rate : 3.4
Compound Interest : 215.334373801618
```

```
# Ruby Program
# Calculate compound interest
class MyMaths
# Method which is take three parameters
# And calculates that compound interest
# Here time is form in year
# rate is form of annual interest rate
def compound_interest(principle, time, rate)
# Display parameters values
print("Principle : ", principle ,"\n")
print("Time : ", time ,"\n")
print("Rate : ", rate ,"\n")
# Calculate interest
amount = principle * ((1 + rate / 100) ** time)
# Display amount
print("Compound Interest : ", amount ,"\n\n")
end
end
def main()
obj = MyMaths.new()
# Test Cases
# Send principle,time and rate
obj.compound_interest(1500, 3, 7.3)
obj.compound_interest(170.4, 7, 3.4)
end
main()
```

#### Output

```
Principle : 1500
Time : 3
Rate : 7.3
Compound Interest : 1853.0640254999998
Principle : 170.4
Time : 7
Rate : 3.4
Compound Interest : 215.334373801618
```

```
/*
Scala Program
Calculate compound interest
*/
class MyMaths
{
//Method which is take three parameters
//And calculates that compound interest
//Here time is form in year
//rate is form of annual interest rate
def compound_interest(principle: Double, time: Double, rate: Double): Unit = {
//Display parameters values
print("Principle : " + principle + "\n");
print("Time : " + time + "\n");
print("Rate : " + rate + "\n");
//Calculate interest
var amount: Double = principle * (Math.pow((1 + rate / 100), time));
//Display amount
print("Compound Interest : " + amount + "\n\n");
}
}
object Main
{
def main(args: Array[String]): Unit = {
var obj: MyMaths = new MyMaths();
//Test Cases
//Send principle,time and rate
obj.compound_interest(1500, 3, 7.3);
obj.compound_interest(170.4, 7, 3.4);
}
}
```

#### Output

```
Principle : 1500.0
Time : 3.0
Rate : 7.3
Compound Interest : 1853.0640254999998
Principle : 170.4
Time : 7.0
Rate : 3.4
Compound Interest : 215.334373801618
```

```
/*
Swift Program
Calculate compound interest
*/
import Foundation
class MyMaths
{
//Method which is take three parameters
//And calculates that compound interest
//Here time is form in year
//rate is form of annual interest rate
func compound_interest(_ principle: Double, _ time: Double, _ rate: Double)
{
print("Principle : ", principle ,"\n", terminator: "");
print("Time : ", time ,"\n", terminator: "");
print("Rate : ", rate ,"\n", terminator: "");
//Calculate interest
let amount: Double = principle * (pow((1 + rate / 100), time));
print("Compound Interest : ", amount ,"\n\n", terminator: "");
}
}
func main()
{
let obj: MyMaths = MyMaths();
//Test Cases
//Send principle,time and rate
obj.compound_interest(1500, 3, 7.3);
obj.compound_interest(170.4, 7, 3.4);
}
main();
```

#### Output

```
Principle : 1500.0
Time : 3.0
Rate : 7.3
Compound Interest : 1853.0640255
Principle : 170.4
Time : 7.0
Rate : 3.4
Compound Interest : 215.334373801618
```

Please share your knowledge to improve code and content standard. Also submit your doubts, and test case. We improve by your feedback. We will try to resolve your query as soon as possible.

## New Comment