Golang 程式,計算給定所有必要值的單利


步驟

  • 讀取本金、利率和時間的數值。
  • 使用公式計算單利。
  • 列印計算得出的利息值。
輸入本金:200
輸入時間(年):5
輸入利率:5
單利是:50
輸入本金:70,000
輸入時間(年):1
輸入利率:4
單利是:2,800

說明

  • 使用者必須輸入本金、利率和時間的值。
  • 公式:(amount*time*rate)/100 用於計算單利。
  • 之後列印單利。

示例

 即時演示

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)
}

輸出

Enter the principal amount: 10000
Enter the time in years: 5
Enter the rate: 5
The simple interest is: 2500

更新日期: 2021 年 7 月 31 日

109 次瀏覽

開啟你的 職業生涯

完成課程並獲得證書

開始
廣告
© . All rights reserved.