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

Here, we are going to demonstrate the use of Printf() and Scanf() function in Golang (Go Language)?
Submitted by Nidhi, on February 15, 2021

Problem Solution:

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.

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.Print("Enter rate: ") 
    fmt.Print("Enter time: ") 
    fmt.Println("Simple interest is: ",si) 


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.

Golang Basic Programs »

Comments and Discussions

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.