- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

# Kotlin Program to Calculate Compound Interest

In this article, we will understand how to calculate the Compound interest. The percentage interest charged on principal and accrued interest is Compound Interest. Rates are higher compared to Simple Interest. Compound Interest is calculated using the formula

principle * (Math.pow((1 + rate / 100), time)) – principle

Below is a demonstration of the same

Suppose our input is

Principle number: 100000 Interest rate: 5 Time period in years: 3

The desired output would be −

The Compound Interest is: 15762.50000000001

## Algorithm

**Step 1**− START**Step 2**− Declare four integer values principalAmount, interestRate, timePeriod, compoundInterest**Step 3**− Define the values for principalAmount, interestRate, timePeriod, compoundInterest.**Step 4**− Perform “principle * (Math.pow((1 + rate / 100), time)) – principle” to calculate the compound interest and store it in a compoundInterest variable**Step 5**− Display compoundInterest**Step 6**− STOP

## Example 1

In this example, we will calculate Compound Interest in Kotlin using the above given formulae. First, declare and set the variable for the Principal amount −

val principalAmount = 10000

Then, set the variables for rate of interest and time period −

val interestRate = 5 val timePeriod = 3

Now, use the above formulae to calculate the Compound Interest

val compoundInterest = principalAmount.toDouble() * Math.pow((1 + interestRate.toDouble()/100.00),timePeriod.toDouble())- principalAmount

Let us see the example to compute the Compound Interest in Kotlin −

fun main() { val principalAmount = 10000 println("Principal amount is defined as: $principalAmount") val interestRate = 5 println("The rate of interest is defined as: $interestRate %") val timePeriod = 3 println("The time period is defined as: $timePeriod years") val compoundInterest = principalAmount.toDouble() * Math.pow((1 + interestRate.toDouble()/100.00),timePeriod.toDouble())- principalAmount println("

Compound Interest is: $compoundInterest") }

## Output

Principal amount is defined as: 10000 The rate of interest is defined as: 5 % The time period is defined as: 3 years Compound Interest is: 1576.250000000002

## Example 2

In this example, we will calculate Compound Interest in Kotlin

fun main() { val principalAmount = 10000 println("Principal amount is defined as: $principalAmount") val interestRate = 5 println("The rate of interest is defined as: $interestRate %") val timePeriod = 3 println("The time period is defined as: $timePeriod years") getCompoundInterest(principalAmount, interestRate, timePeriod) } fun getCompoundInterest(principalAmount: Int, interestRate: Int, timePeriod: Int) { val compoundInterest = principalAmount.toDouble() * Math.pow((1 + interestRate.toDouble()/100.00),timePeriod.toDouble()) - principalAmount println("

Compound Interest is: $compoundInterest") }

## Output

Principal amount is defined as: 10000 The rate of interest is defined as: 5 % The time period is defined as: 3 years Compound Interest is: 1576.250000000002

- Related Questions & Answers
- Java Program to calculate Compound Interest
- Java Program to calculate Simple Interest and Compound Interest
- Java Program to Calculate the Compound Interest
- Calculate compound interest in JavaScript
- C Program for compound interest?
- Python Program for compound interest
- Program to find compound interest in C++
- C Program for the compound interest?
- Compare simple interest and compound interest.
- Java Program to Calculate Simple Interest
- C++ program to find the rate percentage from compound interest of consecutive years
- C++ program to calculate how many years needed to get X rupees with 1% interest
- Calculate interest amount by using formula in C language
- C Program for simple interest?
- Python Program for simple interest
- Simple interest in Python Program