- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- 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 check the power of 4 of a given number
Examples
For example, n = 12 => 12 is not the power of 4.
For example, n = 64 => 64 is the power of 4.
Approach to solve this problem
Step 1 − Define a method that accepts a number n.
Step 2 − Divide log(n) by log(4), store in res.
Step 3 − If the floor of res is same as the res, then print that n is the power of 4.
Step 4 − Else, print that n is not the power of 4.
Example
package main import ( "fmt" "math" ) func CheckPowerOf4(n int){ res := math.Log(float64(n)) / math.Log(float64(4)) if res == math.Floor(res) { fmt.Printf("%d is the power of 4.\n", n) } else { fmt.Printf("%d is not the power of 4.\n", n) } } func main(){ CheckPowerOf4(13) CheckPowerOf4(16) CheckPowerOf4(0) }
Output
13 is not the power of 4. 16 is the power of 4. 0 is the power of 4.
- Related Articles
- Golang Program to find the parity of a given number.
- Golang Program to check whether given positive number is power of 2 or not, without using any branching or loop
- Golang Program to Print the Multiplication Table of a Given Number
- C program to calculate power of a given number
- Golang Program to get the magnitude of the given number
- Write a Golang program to check whether a given number is prime number or not
- Golang Program to check the given number is an odd number using library function
- Golang Program to toggle the Kth of the given number n.
- Java program to calculate the power of a Given number using recursion
- Write a Golang program to check whether a given number is a palindrome or not
- Golang Program to Check if a Number is a Perfect Number
- Golang Program to Check For Armstrong Number
- 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 check if k’th bit is set for a given number or not.

Advertisements