Q:

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

belongs to collection: Golang Basic Programs

0

In this program, we will demonstrate the use of Printf() and Scanf(). In the Go language, we can use Printf() and Scanf() function similar to the C language.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Program/Source Code:

The source code to demonstrate the use of Printf() and Scanf() function is given below. The given program is compiled and executed successfully.

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

Output:

Enter principal: 10000
Enter rate: 3
Enter time: 3
Simple interest is:  900

In the above program, we declare the package main. The main package is used to tell the Go language compiler that the package must be compiled and produced the executable file. Here, we imported the fmt package that includes the files of package fmt then we can use a function related to the fmt package.

Now, we come to the main() function. The main() function is the entry point for the program. Here, we demonstrate the use of Print() and Scanf() function. Both functions are available in the fmt package and we can use both functions similar to C and C++. Here, we calculated the simple interest and print the result on the console screen.

 

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Golang Basic Programs

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
Golang program to get the ASCII value of a charact... >>
<< Golang program to swap two integer numbers...