Skip to content
Home » How to demonstrate the use of Printf() and Scanf() function in Golang

How to demonstrate the use of Printf() and Scanf() function in Golang

Learn about How to demonstrate the use of Printf() and Scanf() function in Golang in the below code example. Also refer the comments in the code snippet to get a detailed view about what’s actually happening.

How to demonstrate the use of Printf() and Scanf() function in Golang

// Golang program to demonstrate the use of 
// printf() and scanf() function.

package main
import "fmt"

func main() {
    //Declare 4 integer type variables.
    var p int
    var r int
    var t int
    var si int
    
    
    fmt.Print("Enter principal: ") 
    fmt.Scanf("%d",&p)
    
    fmt.Print("Enter rate: ") 
    fmt.Scanf("%d",&r)
    
    fmt.Print("Enter time: ") 
    fmt.Scanf("%d",&t)
    
    si=(p*r*t)/100
    
    fmt.Println("Simple interest is: ",si) 
}

Hope above code works for you and Refer the below Related Codes to gain more insights. Happy coding and come back again.

Similar Codes :
How to get the ASCII value of a character in Golang
How to read and print an integer variable in Golang