# Check if two numbers have same length

Here given code implementation process.

``````// C Program for
// Check if two numbers have same length
#include <stdio.h>

int absValue(int num)
{
if (num < 0)
{
return -num;
}
return num;
}
void isSameLength(int a, int b)
{
int x = absValue(a);
int y = absValue(b);
printf("\n Given number a : %d  b : %d", a, b);
while (x > 0 && y > 0)
{
// Reduce the last digit
x = x / 10;
y = y / 10;
}
if (x == 0 && y == 0)
{
printf("\n Same length ");
}
else
{
printf("\n Not same length ");
}
}
int main(int argc, char const *argv[])
{
// Test
isSameLength(2311, 1221);
isSameLength(1311, 111);
isSameLength(1321, -1113);
return 0;
}``````

#### Output

`````` Given number a : 2311  b : 1221
Same length
Given number a : 1311  b : 111
Not same length
Given number a : 1321  b : -1113
Same length``````
``````// Java program for
// Check if two numbers have same length
public class NumberLength
{
public int absValue(int num)
{
if (num < 0)
{
return -num;
}
return num;
}
public void isSameLength(int a, int b)
{
int x = absValue(a);
int y = absValue(b);
System.out.print("\n Given number a : " + a + " b : " + b);
while (x > 0 && y > 0)
{
// Reduce the last digit
x = x / 10;
y = y / 10;
}
if (x == 0 && y == 0)
{
System.out.print("\n Same length ");
}
else
{
System.out.print("\n Not same length ");
}
}
public static void main(String[] args)
{
// Test
}
}``````

#### Output

`````` Given number a : 2311 b : 1221
Same length
Given number a : 1311 b : 111
Not same length
Given number a : 1321 b : -1113
Same length``````
``````// Include header file
#include <iostream>
using namespace std;
// C++ program for
// Check if two numbers have same length
class NumberLength
{
public: int absValue(int num)
{
if (num < 0)
{
return -num;
}
return num;
}
void isSameLength(int a, int b)
{
int x = this->absValue(a);
int y = this->absValue(b);
cout << "\n Given number a : " << a << " b : " << b;
while (x > 0 && y > 0)
{
// Reduce the last digit
x = x / 10;
y = y / 10;
}
if (x == 0 && y == 0)
{
cout << "\n Same length ";
}
else
{
cout << "\n Not same length ";
}
}
};
int main()
{
// Test
return 0;
}``````

#### Output

`````` Given number a : 2311 b : 1221
Same length
Given number a : 1311 b : 111
Not same length
Given number a : 1321 b : -1113
Same length``````
``````package main
import "fmt"
// Go program for
// Check if two numbers have same length
type NumberLength struct {}
func getNumberLength() * NumberLength {
var me *NumberLength = &NumberLength {}
return me
}
func(this NumberLength) absValue(num int) int {
if num < 0 {
return -num
}
return num
}
func(this NumberLength) isSameLength(a, b int) {
var x int = this.absValue(a)
var y int = this.absValue(b)
fmt.Print("\n Given number a : ", a, " b : ", b)
for (x > 0 && y > 0) {
// Reduce the last digit
x = x / 10
y = y / 10
}
if x == 0 && y == 0 {
fmt.Print("\n Same length ")
} else {
fmt.Print("\n Not same length ")
}
}
func main() {
var task * NumberLength = getNumberLength()
// Test
}``````

#### Output

`````` Given number a : 2311 b : 1221
Same length
Given number a : 1311 b : 111
Not same length
Given number a : 1321 b : -1113
Same length``````
``````// Include namespace system
using System;
// Csharp program for
// Check if two numbers have same length
public class NumberLength
{
public int absValue(int num)
{
if (num < 0)
{
return -num;
}
return num;
}
public void isSameLength(int a, int b)
{
int x = this.absValue(a);
int y = this.absValue(b);
Console.Write("\n Given number a : " + a + " b : " + b);
while (x > 0 && y > 0)
{
// Reduce the last digit
x = x / 10;
y = y / 10;
}
if (x == 0 && y == 0)
{
Console.Write("\n Same length ");
}
else
{
Console.Write("\n Not same length ");
}
}
public static void Main(String[] args)
{
// Test
}
}``````

#### Output

`````` Given number a : 2311 b : 1221
Same length
Given number a : 1311 b : 111
Not same length
Given number a : 1321 b : -1113
Same length``````
``````<?php
// Php program for
// Check if two numbers have same length
class NumberLength
{
public	function absValue(\$num)
{
if (\$num < 0)
{
return -\$num;
}
return \$num;
}
public	function isSameLength(\$a, \$b)
{
\$x = \$this->absValue(\$a);
\$y = \$this->absValue(\$b);
echo("\n Given number a : ".\$a.
" b : ".\$b);
while (\$x > 0 && \$y > 0)
{
// Reduce the last digit
\$x = (int)(\$x / 10);
\$y = (int)(\$y / 10);
}
if (\$x == 0 && \$y == 0)
{
echo("\n Same length ");
}
else
{
echo("\n Not same length ");
}
}
}

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

#### Output

`````` Given number a : 2311 b : 1221
Same length
Given number a : 1311 b : 111
Not same length
Given number a : 1321 b : -1113
Same length``````
``````// Node JS program for
// Check if two numbers have same length
class NumberLength
{
absValue(num)
{
if (num < 0)
{
return -num;
}
return num;
}
isSameLength(a, b)
{
var x = this.absValue(a);
var y = this.absValue(b);
process.stdout.write("\n Given number a : " + a + " b : " + b);
while (x > 0 && y > 0)
{
// Reduce the last digit
x = parseInt(x / 10);
y = parseInt(y / 10);
}
if (x == 0 && y == 0)
{
process.stdout.write("\n Same length ");
}
else
{
process.stdout.write("\n Not same length ");
}
}
}

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

#### Output

`````` Given number a : 2311 b : 1221
Same length
Given number a : 1311 b : 111
Not same length
Given number a : 1321 b : -1113
Same length``````
``````#  Python 3 program for
#  Check if two numbers have same length
class NumberLength :
def absValue(self, num) :
if (num < 0) :
return -num

return num

def isSameLength(self, a, b) :
x = self.absValue(a)
y = self.absValue(b)
print("\n Given number a : ", a ," b : ", b, end = "")
while (x > 0 and y > 0) :
#  Reduce the last digit
x = int(x / 10)
y = int(y / 10)

if (x == 0 and y == 0) :
print("\n Same length ", end = "")
else :
print("\n Not same length ", end = "")

def main() :
#  Test

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

#### Output

`````` Given number a :  2311  b :  1221
Same length
Given number a :  1311  b :  111
Not same length
Given number a :  1321  b :  -1113
Same length``````
``````#  Ruby program for
#  Check if two numbers have same length
class NumberLength
def absValue(num)
if (num < 0)
return -num
end

return num
end

def isSameLength(a, b)
x = self.absValue(a)
y = self.absValue(b)
print("\n Given number a : ", a ," b : ", b)
while (x > 0 && y > 0)
#  Reduce the last digit
x = x / 10
y = y / 10
end

if (x == 0 && y == 0)
print("\n Same length ")
else

print("\n Not same length ")
end

end

end

def main()
#  Test
end

main()``````

#### Output

`````` Given number a : 2311 b : 1221
Same length
Given number a : 1311 b : 111
Not same length
Given number a : 1321 b : -1113
Same length ``````
``````// Scala program for
// Check if two numbers have same length
class NumberLength()
{
def absValue(num: Int): Int = {
if (num < 0)
{
return -num;
}
return num;
}
def isSameLength(a: Int, b: Int): Unit = {
var x: Int = absValue(a);
var y: Int = absValue(b);
print("\n Given number a : " + a + " b : " + b);
while (x > 0 && y > 0)
{
// Reduce the last digit
x = x / 10;
y = y / 10;
}
if (x == 0 && y == 0)
{
print("\n Same length ");
}
else
{
print("\n Not same length ");
}
}
}
object Main
{
def main(args: Array[String]): Unit = {
var task: NumberLength = new NumberLength();
// Test
}
}``````

#### Output

`````` Given number a : 2311 b : 1221
Same length
Given number a : 1311 b : 111
Not same length
Given number a : 1321 b : -1113
Same length``````
``````// Swift 4 program for
// Check if two numbers have same length
class NumberLength
{
func absValue(_ num: Int) -> Int
{
if (num < 0)
{
return -num;
}
return num;
}
func isSameLength(_ a: Int, _ b: Int)
{
var x: Int = self.absValue(a);
var y: Int = self.absValue(b);
print("\n Given number a : ", a ," b : ", b, terminator: "");
while (x > 0 && y > 0)
{
// Reduce the last digit
x = x / 10;
y = y / 10;
}
if (x == 0 && y == 0)
{
print("\n Same length ", terminator: "");
}
else
{
print("\n Not same length ", terminator: "");
}
}
}
func main()
{
// Test
}
main();``````

#### Output

`````` Given number a :  2311  b :  1221
Same length
Given number a :  1311  b :  111
Not same length
Given number a :  1321  b :  -1113
Same length``````
``````// Kotlin program for
// Check if two numbers have same length
class NumberLength
{
fun absValue(num: Int): Int
{
if (num < 0)
{
return -num;
}
return num;
}
fun isSameLength(a: Int, b: Int): Unit
{
var x: Int = this.absValue(a);
var y: Int = this.absValue(b);
print("\n Given number a : " + a + " b : " + b);
while (x > 0 && y > 0)
{
// Reduce the last digit
x = x / 10;
y = y / 10;
}
if (x == 0 && y == 0)
{
print("\n Same length ");
}
else
{
print("\n Not same length ");
}
}
}
fun main(args: Array < String > ): Unit
{
// Test
}``````

#### Output

`````` Given number a : 2311 b : 1221
Same length
Given number a : 1311 b : 111
Not same length
Given number a : 1321 b : -1113
Same length``````

## 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.