Simple interest in go lang

package main
import "fmt"
func main() {
var p int
var r float32
var t int
fmt.Print("Enter principal, rate and time: ")
si := float32(p) * float32(t) * r / 100
fmt.Printf("Simple interest: %.2f",si)
  • Most of the things of the above program are already discussed. bur some of the important statement is discussed here.
si := float32(p) * float32(t) * r / 100

  • The above program statement performs a simple calculation p * t * r / 100 and stores the result in variable si
  • In go lang in a single expression multiple types are not allowed, so we need to convert p and t into float32 type and expression p * t * r becomes a float32 type expression.
  • To typecast a variable we use the following syntax

  •  In the above program snippet to print the result fmt.Printf("Simple interest : %.2f",si).
  • Printf() is a function used to print the formatted output.
  • %.2f prints a floating point value with only 2 decimal places.


Popular posts from this blog

Program to calculate telephone bill

Sum of two numbers in go lang

Program to check a year is leap year or not.

String in golang


Arrays in C Language

Reserved Words in Java

Data types in Java

Pointers in C Language

Literals in Java