- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

# Golang Program to get the imaginary part of the given complex number

In this tutorial, we are going to learn about how to get imaginary part of the complex number in Go programming language.

Complex Number = Real Number + Imaginary Number

In a complex number the real number multiplying ‘I’ is the imaginary part of a complex number. The imaginary part is the multiple of i. so if the letter z to stands for a complex number and z = a + bi where the real number ‘a’ is called the real part of the complex number a + bi and the real number ‘b’ is called its imaginary part.

### Syntax

func imag(c ComplexType) FloatType

The imag() built-in function returns the imaginary part of the complex number of type float32.

## Find the Imaginary part of a Complex number using imag() Function

### Algorithm

**Step 1** − Import the package fmt

**Step 2** − Start function main()

**Step 3** − Define and assign the variable

**Step 4** − Calling the built-in function imag()

**Step 5** − Print the imaginary part of the complex number using fmt.Println()

### Example

In this example, we are going to find the imaginary part of the complex number using imag() function

// GOLANG PROGRAM TO FIND THE IMAGINARY PART OF A GIVEN COMPLEX NUMBER package main // fmt package provides the function to print anything import ( "fmt" ) func main() { // defining and assigning a value to the variable complex_num := 5 + 4i // Calling the built-in function imag() a := imag(complex_num) // Print the imaginary part of the complex number fmt.Println("Imaginary part of the given",complex_num,"complex number: ", a) // Declare a complex64 variable var number complex64 // Declare a float variable var b float32 // Assign a value to the complex variable number = 7 + 9i // Calling the built-in function imag() b = imag(number) // Print the imaginary part of the complex number fmt.Println("Imaginary part of the given",number,"complex number: ", b) }

### Output

Imaginary part of the given (5+4i) complex number: 4 Imaginary part of the given (7+9i) complex number: 9

### Description of code

In the above program, we first declare the package main.

We imported the fmt package that includes the files of package fmt which provides the function to print anything.

We start the function main()

Next define and initialize the complex type variable by assigning a value to it

Then calling the built-in function imag() to find the imaginary part of the given complex number

In the end we print the imaginary part of the complex number using fmt.Println()

## Find the Imaginary part of a Complex Number along with its type

### Algorithm

**Step 1** − Import the package fmt

**Step 2** − Start function main()

**Step 3** − Define and assign the complex numbers

**Step 4** − Calling the built-in function imag()

**Step 5** − Print the imaginary part of the complex number using fmt.Printf()

### Example

In this example we are going to find the imaginary part of a complex number along with its variable type

// GOLANG PROGRAM TO FIND THE IMAGINARY PART OF A GIVEN COMPLEX NUMBER package main // fmt package provides the function to print anything import ( "fmt" ) func main() { // Declare and assign complex numbers var x complex128 = complex(1, 27) var y complex128 = complex(3, 9) var z complex128 = complex(5, 6) // Extracting the imaginary part and // printing its value and type imag_x := imag(x) imag_y := imag(y) imag_z := imag(z) fmt.Println("Imaginary part of the given complex number: x : %v %T\n", imag_x, imag_x) fmt.Println("Imaginary part of the given complex number: y : %v %T\n", imag_y, imag_y) fmt.Println("Imaginary part of the given complex number: z : %v %T\n", imag_z, imag_z) }

### Output

Imaginary part of the given complex number: x : 27 float64 Imaginary part of the given complex number: y : 9 float64 Imaginary part of the given complex number: z : 6 float64

### Description of code

In the above program, we first declare the package main.

We imported the fmt package that includes the files of package fmt which provides the function to print anything.

We start the function main()

Next we define and initialize the complex numbers by assigning a value to it

Next calling the built-in function imag() to find the imaginary part of the given complex number

In the end we print the imaginary part of the complex number along with its type using fmt.Printf()

### Conclusion

We have successfully compiled and executed 2 examples of the Golang code on how to find the imaginary parts of a given complex number in Go programming language.

- Related Questions & Answers
- Change the imaginary part of the complex argument in Python
- Return the imaginary part of the complex argument in Python
- Get the Imaginary part from the masked array in Numpy
- Golang Program to toggle the Kth of the given number n.
- Golang Program to find the parity of a given number.
- Golang Program to Print the Multiplication Table of a Given Number
- Golang Program to check the power of 4 of a given number
- How to construct a complex tensor with the given real and imaginary parts in PyTorch?
- Return the real part of the complex argument in Python
- Change the real part of the complex argument in Python
- Write a Golang program to find the factorial of a given number (Using Recursion)
- Write a Golang program to find the sum of digits for a given number
- Golang Program to count the number of flips to convert a given integer to another.
- Golang Program to Count the Number of Digits in a Number
- How to get the port number part of the href attribute of an area in JavaScript?
- Golang Program to Calculate the Average of Numbers in a Given List