R Program to Calculate Simple Interest
Last Updated :
21 Feb, 2024
Basically, Simple Interest is a quick method to calculate the interest charge of a loan. It is determined by multiplying the principal amount by the daily interest rate by the number of days which elapse between the payments. It gets estimated day to day-with the help of mathematical terms.
we will create a program to calculate simple interest in R Programming Language.
Formula:
Simple Interest = (P x R x T)/100
The Algorithm is:
- First, we need to define the Principle, Rate, and Interest
- Then, need to Apply the formula
- Finally, we can print the Simple Interest.
Here we create an R program to calculate Simple Interest:
R
calculate_simple_interest <- function (principal, rate, time) {
simple_interest <- (principal * rate * time) / 100
return (simple_interest)
}
principal <- 10000
rate <- 12
time <- 5
result <- calculate_simple_interest (principal, rate, time)
cat ("Simple Interest:", result)
|
Output:
Simple Interest: 6000
In the mentioned program, define a function like ‘calculate_simple_interest‘ which takes three arguments called ‘principal‘, ‘rate‘, and ‘time’. Then the function used the Formula for Calculating the Simple Interest.
Example 2: Here’s another approach to calculating simple interest in R using a more concise method
R
principal <- 1000
rate <- 5
time <- 2
simple_interest <- (principal * rate * time) / 100
cat ("Principal amount: $", principal, "\n")
cat ("Rate of interest: ", rate, "%\n")
cat ("Time: ", time, " years\n")
cat ("Simple Interest: $", simple_interest, "\n")
|
Output:
Principal amount: $ 1000
Rate of interest: 5 %
Time: 2 years
Simple Interest: $ 100
Share your thoughts in the comments
Please Login to comment...