R Program to Calculate Simple Interest
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
# Function to calculate the Simple Interest calculate_simple_interest <- function (principal, rate, time) { # Simple Interest formula: SI = P * R * T / 100 simple_interest <- (principal * rate * time) / 100 return (simple_interest) } # Input values principal <- 10000 rate <- 12 time <- 5 # Calculate the simple interest using the function result <- calculate_simple_interest (principal, rate, time) # Display the result 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
# Input values principal <- 1000 rate <- 5 time <- 2 # Calculate simple interest simple_interest <- (principal * rate * time) / 100 # Print the result 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