Golang Program to Compute Simple Interest Given all the Required Values



Steps

  • Read the values for principal amount, rate and time.
  • Using the formula, compute the simple interest.
  • Print the value for the computed interest.
Enter the principal amount: 200
Enter the time(years): 5
Enter the rate: 5
The simple interest is: 50
Enter the principal amount: 70000
Enter the time(years): 1
Enter the rate: 4
The simple interest is: 2800

Explanation

  • User must enter the values for the principal amount, rate and time.
  • The formula: (amount*time*rate)/100 is used to compute the simple interest.
  • The simple interest is later printed.

Example

 Live Demo

package main import "fmt" func main() {    var principal, time, rate int    fmt.Print("Enter the principal amount: ")    fmt.Scanf("%d", &principal)    fmt.Print("Enter the time in years: ")    fmt.Scanf("%d", &time)    fmt.Print("Enter the rate: ")    fmt.Scanf("%d", &rate)    simpleInterest :=(principal*time*rate)/100    fmt.Println("The simple interest is: ", simpleInterest) }

Output

Enter the principal amount: 10000 Enter the time in years: 5 Enter the rate: 5 The simple interest is: 2500
Updated on: 2021-07-31T15:11:05+05:30

166 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements