# Checking whether a number is a power of 10

Here given code implementation process.

``````// C Program
// Checking whether a number is a power of 10
#include <stdio.h>

void isPowerOf10(int num)
{
if (num <= 0)
{
// When num not valid
return;
}
int n = num;
// This loop is executing when n is greater than 9.
// And n is divisible by 10.
while (n > 9 && n % 10 == 0)
{
// Remove last digit
n = n / 10;
}
if (n == 1)
{
printf("\n Given number (%d) is power of 10", num);
}
else
{
printf("\n Given number (%d) is not power of 10", num);
}
}
int main()
{
// Test Case
isPowerOf10(100000);
isPowerOf10(12000);
isPowerOf10(1);
isPowerOf10(100);
isPowerOf10(100010);
return 0;
}``````

#### Output

`````` Given number (100000) is power of 10
Given number (12000) is not power of 10
Given number (1) is power of 10
Given number (100) is power of 10
Given number (100010) is not power of 10``````
``````// Java program for
// Checking whether a number is a power of 10
public class Power
{
public void isPowerOf10(int num)
{
if (num <= 0)
{
// When num not valid
return;
}
int n = num;
// This loop is executing when n is greater than 9.
// And n is divisible by 10.
while (n > 9 && n % 10 == 0)
{
// Remove last digit
n = n / 10;
}
if (n == 1)
{
System.out.print("\n Given number (" +
num + ") is power of 10");
}
else
{
System.out.print("\n Given number (" +
num + ") is not power of 10");
}
}
public static void main(String[] args)
{
// Test Case
}
}``````

#### Output

`````` Given number (100000) is power of 10
Given number (12000) is not power of 10
Given number (1) is power of 10
Given number (100) is power of 10
Given number (100010) is not power of 10``````
``````// Include header file
#include <iostream>
using namespace std;
// C++ program for
// Checking whether a number is a power of 10
class Power
{
public: void isPowerOf10(int num)
{
if (num <= 0)
{
// When num not valid
return;
}
int n = num;
// This loop is executing when n is greater than 9.
// And n is divisible by 10.
while (n > 9 && n % 10 == 0)
{
// Remove last digit
n = n / 10;
}
if (n == 1)
{
cout << "\n Given number ("
<< num << ") is power of 10";
}
else
{
cout << "\n Given number ("
<< num << ") is not power of 10";
}
}
};
int main()
{
// Test Case
return 0;
}``````

#### Output

`````` Given number (100000) is power of 10
Given number (12000) is not power of 10
Given number (1) is power of 10
Given number (100) is power of 10
Given number (100010) is not power of 10``````
``````// Include namespace system
using System;
// Csharp program for
// Checking whether a number is a power of 10
public class Power
{
public void isPowerOf10(int num)
{
if (num <= 0)
{
// When num not valid
return;
}
int n = num;
// This loop is executing when n is greater than 9.
// And n is divisible by 10.
while (n > 9 && n % 10 == 0)
{
// Remove last digit
n = n / 10;
}
if (n == 1)
{
Console.Write("\n Given number (" + num + ") is power of 10");
}
else
{
Console.Write("\n Given number (" + num + ") is not power of 10");
}
}
public static void Main(String[] args)
{
// Test Case
}
}``````

#### Output

`````` Given number (100000) is power of 10
Given number (12000) is not power of 10
Given number (1) is power of 10
Given number (100) is power of 10
Given number (100010) is not power of 10``````
``````package main
import "fmt"
// Go program for
// Checking whether a number is a power of 10
type Power struct {}
func getPower() * Power {
var me *Power = &Power {}
return me
}
func(this Power) isPowerOf10(num int) {
if num <= 0 {
// When num not valid
return
}
var n int = num
// This loop is executing when n is greater than 9.
// And n is divisible by 10.
for (n > 9 && n % 10 == 0) {
// Remove last digit
n = n / 10
}
if n == 1 {
fmt.Print("\n Given number (",
num, ") is power of 10")
} else {
fmt.Print("\n Given number (",
num, ") is not power of 10")
}
}
func main() {
var task * Power = getPower()
// Test Case
}``````

#### Output

`````` Given number (100000) is power of 10
Given number (12000) is not power of 10
Given number (1) is power of 10
Given number (100) is power of 10
Given number (100010) is not power of 10``````
``````<?php
// Php program for
// Checking whether a number is a power of 10
class Power
{
public	function isPowerOf10(\$num)
{
if (\$num <= 0)
{
// When num not valid
return;
}
\$n = \$num;
// This loop is executing when n is greater than 9.
// And n is divisible by 10.
while (\$n > 9 && \$n % 10 == 0)
{
// Remove last digit
\$n = (int)(\$n / 10);
}
if (\$n == 1)
{
echo("\n Given number (".\$num.
") is power of 10");
}
else
{
echo("\n Given number (".\$num.
") is not power of 10");
}
}
}

function main()
{
// Test Case
}
main();``````

#### Output

`````` Given number (100000) is power of 10
Given number (12000) is not power of 10
Given number (1) is power of 10
Given number (100) is power of 10
Given number (100010) is not power of 10``````
``````// Node JS program for
// Checking whether a number is a power of 10
class Power
{
isPowerOf10(num)
{
if (num <= 0)
{
// When num not valid
return;
}
var n = num;
// This loop is executing when n is greater than 9.
// And n is divisible by 10.
while (n > 9 && n % 10 == 0)
{
// Remove last digit
n = parseInt(n / 10);
}
if (n == 1)
{
process.stdout.write("\n Given number (" +
num + ") is power of 10");
}
else
{
process.stdout.write("\n Given number (" +
num + ") is not power of 10");
}
}
}

function main()
{
// Test Case
}
main();``````

#### Output

`````` Given number (100000) is power of 10
Given number (12000) is not power of 10
Given number (1) is power of 10
Given number (100) is power of 10
Given number (100010) is not power of 10``````
``````#  Python 3 program for
#  Checking whether a number is a power of 10
class Power :
def isPowerOf10(self, num) :
if (num <= 0) :
#  When num not valid
return

n = num
#  This loop is executing when n is greater than 9.
#  And n is divisible by 10.
while (n > 9 and n % 10 == 0) :
#  Remove last digit
n = int(n / 10)

if (n == 1) :
print("\n Given number (",
num ,") is power of 10", end = "")
else :
print("\n Given number (",
num ,") is not power of 10", end = "")

def main() :
#  Test Case

if __name__ == "__main__": main()``````

#### Output

`````` Given number ( 100000 ) is power of 10
Given number ( 12000 ) is not power of 10
Given number ( 1 ) is power of 10
Given number ( 100 ) is power of 10
Given number ( 100010 ) is not power of 10``````
``````#  Ruby program for
#  Checking whether a number is a power of 10
class Power
def isPowerOf10(num)
if (num <= 0)
#  When num not valid
return
end

n = num
#  This loop is executing when n is greater than 9.
#  And n is divisible by 10.
while (n > 9 && n % 10 == 0)
#  Remove last digit
n = n / 10
end

if (n == 1)
print("\n Given number (",
num ,") is power of 10")
else

print("\n Given number (",
num ,") is not power of 10")
end

end

end

def main()
#  Test Case
end

main()``````

#### Output

`````` Given number (100000) is power of 10
Given number (12000) is not power of 10
Given number (1) is power of 10
Given number (100) is power of 10
Given number (100010) is not power of 10``````
``````// Scala program for
// Checking whether a number is a power of 10
class Power()
{
def isPowerOf10(num: Int): Unit = {
if (num <= 0)
{
// When num not valid
return;
}
var n: Int = num;
// This loop is executing when n is greater than 9.
// And n is divisible by 10.
while (n > 9 && n % 10 == 0)
{
// Remove last digit
n = n / 10;
}
if (n == 1)
{
print("\n Given number (" + num + ") is power of 10");
}
else
{
print("\n Given number (" + num + ") is not power of 10");
}
}
}
object Main
{
def main(args: Array[String]): Unit = {
var task: Power = new Power();
// Test Case
}
}``````

#### Output

`````` Given number (100000) is power of 10
Given number (12000) is not power of 10
Given number (1) is power of 10
Given number (100) is power of 10
Given number (100010) is not power of 10``````
``````// Swift 4 program for
// Checking whether a number is a power of 10
class Power
{
func isPowerOf10(_ num: Int)
{
if (num <= 0)
{
// When num not valid
return;
}
var n: Int = num;
// This loop is executing when n is greater than 9.
// And n is divisible by 10.
while (n > 9 && n % 10 == 0)
{
// Remove last digit
n = n / 10;
}
if (n == 1)
{
print("\n Given number (",
num ,") is power of 10", terminator: "");
}
else
{
print("\n Given number (",
num ,") is not power of 10", terminator: "");
}
}
}
func main()
{
// Test Case
}
main();``````

#### Output

`````` Given number ( 100000 ) is power of 10
Given number ( 12000 ) is not power of 10
Given number ( 1 ) is power of 10
Given number ( 100 ) is power of 10
Given number ( 100010 ) is not power of 10``````
``````// Kotlin program for
// Checking whether a number is a power of 10
class Power
{
fun isPowerOf10(num: Int): Unit
{
if (num <= 0)
{
// When num not valid
return;
}
var n: Int = num;
// This loop is executing when n is greater than 9.
// And n is divisible by 10.
while (n > 9 && n % 10 == 0)
{
// Remove last digit
n = n / 10;
}
if (n == 1)
{
print("\n Given number (" +
num + ") is power of 10");
}
else
{
print("\n Given number (" +
num + ") is not power of 10");
}
}
}
fun main(args: Array < String > ): Unit
{
// Test Case
}``````

#### Output

`````` Given number (100000) is power of 10
Given number (12000) is not power of 10
Given number (1) is power of 10
Given number (100) is power of 10
Given number (100010) is not power of 10``````

## Comment

Please share your knowledge to improve code and content standard. Also submit your doubts, and test case. We improve by your feedback. We will try to resolve your query as soon as possible.