# Stepping Numbers

Here given code implementation process.

``````/*
C program
Stepping Numbers
*/

#include <stdio.h>

// Check that number is stepping number
int isStepping(int number)
{
if((number > -10 && number < 10))
{
// When number is single digit number
return 1;
}

int n = number;

if(n < 0)
{
n = - number;
}
// Get last digit
int digit1 = n % 10;
int digit2 = 0;

n = n / 10;

while(n != 0)
{
// Get last digit
digit2 = n % 10;

if(digit2+1 == digit1  || digit2-1 == digit1)
{

n = n / 10;

digit1 = digit2;
}
else
{
return 0;
}
}
return 1;
}

// This is handling request to find the Stepping number
void findSteppingNo(int first,int last)
{
if(last < first)
{
// Change the order
findSteppingNo(last,first);
}
else
{
printf("\n Stepping Number in %d to %d is \n",first,last);

for (int i = first; i < last ; ++i)
{
if(isStepping(i)==1)
{
printf("  %d",i);
}
}
}
printf("\n");
}
int main()
{

//Test Case
findSteppingNo(-8, 15);
findSteppingNo(1, 50);
return 0;
} ``````

#### Output

`````` Stepping Number in -8 to 15 is
-8  -7  -6  -5  -4  -3  -2  -1  0  1  2  3  4  5  6  7  8  9  10  12

Stepping Number in 1 to 50 is
1  2  3  4  5  6  7  8  9  10  12  21  23  32  34  43  45``````
``````/*
Java Program
Stepping Numbers
*/
public class SteppingNumber
{
// Check that number is stepping number
public boolean isStepping(int number)
{
if ((number > -10 && number < 10))
{
// When number is single digit number
return true;
}
int n = number;
if (n < 0)
{
n = -number;
}
// Get last digit
int digit1 = n % 10;
int digit2 = 0;
n = n / 10;
while (n != 0)
{
// Get last digit
digit2 = n % 10;
if (digit2 + 1 == digit1 || digit2 - 1 == digit1)
{
n = n / 10;
digit1 = digit2;
}
else
{
return false;
}
}
return true;
}
// This is handling request to find the Stepping number
public void findSteppingNo(int first, int last)
{
if (last < first)
{
// Change the order
findSteppingNo(last, first);
}
else
{
System.out.print("\n Stepping Number in " + first + " to " + last + " is \n");
for (int i = first; i < last; ++i)
{
if (isStepping(i) == true)
{
System.out.print("  " + i);
}
}
}
System.out.print("\n");
}
public static void main(String[] args)
{
SteppingNumber obj = new SteppingNumber();
//Test Case
obj.findSteppingNo(-8, 15);
obj.findSteppingNo(1, 50);
}
}``````

#### Output

`````` Stepping Number in -8 to 15 is
-8  -7  -6  -5  -4  -3  -2  -1  0  1  2  3  4  5  6  7  8  9  10  12

Stepping Number in 1 to 50 is
1  2  3  4  5  6  7  8  9  10  12  21  23  32  34  43  45``````
``````// Include header file
#include <iostream>

using namespace std;
/*
C++ Program
Stepping Numbers
*/
class SteppingNumber
{
public:
//  Check that number is stepping number
bool isStepping(int number)
{
if ((number > -10 && number < 10))
{
//  When number is single digit number
return true;
}
int n = number;
if (n < 0)
{
n = -number;
}
//  Get last digit
int digit1 = n % 10;
int digit2 = 0;
n = n / 10;
while (n != 0)
{
//  Get last digit
digit2 = n % 10;
if (digit2 + 1 == digit1 || digit2 - 1 == digit1)
{
n = n / 10;
digit1 = digit2;
}
else
{
return false;
}
}
return true;
}
//  This is handling request to find the Stepping number
void findSteppingNo(int first, int last)
{
if (last < first)
{
//  Change the order
this->findSteppingNo(last, first);
}
else
{
cout << "\n Stepping Number in " << first << " to " << last << " is \n";
for (int i = first; i < last; ++i)
{
if (this->isStepping(i) == true)
{
cout << "  " << i;
}
}
}
cout << "\n";
}
};
int main()
{
SteppingNumber obj = SteppingNumber();
// Test Case
obj.findSteppingNo(-8, 15);
obj.findSteppingNo(1, 50);
return 0;
}``````

#### Output

`````` Stepping Number in -8 to 15 is
-8  -7  -6  -5  -4  -3  -2  -1  0  1  2  3  4  5  6  7  8  9  10  12

Stepping Number in 1 to 50 is
1  2  3  4  5  6  7  8  9  10  12  21  23  32  34  43  45``````
``````// Include namespace system
using System;
/*
C# Program
Stepping Numbers
*/
public class SteppingNumber
{
//  Check that number is stepping number
public Boolean isStepping(int number)
{
if ((number > -10 && number < 10))
{
//  When number is single digit number
return true;
}
int n = number;
if (n < 0)
{
n = -number;
}
//  Get last digit
int digit1 = n % 10;
int digit2 = 0;
n = n / 10;
while (n != 0)
{
//  Get last digit
digit2 = n % 10;
if (digit2 + 1 == digit1 || digit2 - 1 == digit1)
{
n = n / 10;
digit1 = digit2;
}
else
{
return false;
}
}
return true;
}
//  This is handling request to find the Stepping number
public void findSteppingNo(int first, int last)
{
if (last < first)
{
//  Change the order
findSteppingNo(last, first);
}
else
{
Console.Write("\n Stepping Number in " + first + " to " + last + " is \n");
for (int i = first; i < last; ++i)
{
if (isStepping(i) == true)
{
Console.Write("  " + i);
}
}
}
Console.Write("\n");
}
public static void Main(String[] args)
{
SteppingNumber obj = new SteppingNumber();
// Test Case
obj.findSteppingNo(-8, 15);
obj.findSteppingNo(1, 50);
}
}``````

#### Output

`````` Stepping Number in -8 to 15 is
-8  -7  -6  -5  -4  -3  -2  -1  0  1  2  3  4  5  6  7  8  9  10  12

Stepping Number in 1 to 50 is
1  2  3  4  5  6  7  8  9  10  12  21  23  32  34  43  45``````
``````<?php
/*
Php Program
Stepping Numbers
*/
class SteppingNumber
{
//  Check that number is stepping number
public function isStepping(\$number)
{
if ((\$number > -10 && \$number < 10))
{
//  When number is single digit number
return true;
}
\$n = \$number;
if (\$n < 0)
{
\$n = -\$number;
}
//  Get last digit
\$digit1 = \$n % 10;
\$digit2 = 0;
\$n = intval(\$n / 10);
while (\$n != 0)
{
//  Get last digit
\$digit2 = \$n % 10;
if (\$digit2 + 1 == \$digit1 || \$digit2 - 1 == \$digit1)
{
\$n = intval(\$n / 10);
\$digit1 = \$digit2;
}
else
{
return false;
}
}
return true;
}
//  This is handling request to find the Stepping number
public	function findSteppingNo(\$first, \$last)
{
if (\$last < \$first)
{
//  Change the order
\$this->findSteppingNo(\$last, \$first);
}
else
{
echo "\n Stepping Number in ". \$first ." to ". \$last ." is \n";
for (\$i = \$first; \$i < \$last; ++\$i)
{
if (\$this->isStepping(\$i) == true)
{
echo "  ". \$i;
}
}
}
echo "\n";
}
}

function main()
{
\$obj = new SteppingNumber();
// Test Case
\$obj->findSteppingNo(-8, 15);
\$obj->findSteppingNo(1, 50);
}
main();``````

#### Output

`````` Stepping Number in -8 to 15 is
-8  -7  -6  -5  -4  -3  -2  -1  0  1  2  3  4  5  6  7  8  9  10  12

Stepping Number in 1 to 50 is
1  2  3  4  5  6  7  8  9  10  12  21  23  32  34  43  45``````
``````/*
Node Js Program
Stepping Numbers
*/
class SteppingNumber
{
//  Check that number is stepping number
isStepping(number)
{
if ((number > -10 && number < 10))
{
//  When number is single digit number
return true;
}
var n = number;
if (n < 0)
{
n = -number;
}
//  Get last digit
var digit1 = n % 10;
var digit2 = 0;
n = parseInt(n / 10);
while (n != 0)
{
//  Get last digit
digit2 = n % 10;
if (digit2 + 1 == digit1 || digit2 - 1 == digit1)
{
n = parseInt(n / 10);
digit1 = digit2;
}
else
{
return false;
}
}
return true;
}
//  This is handling request to find the Stepping number
findSteppingNo(first, last)
{
if (last < first)
{
//  Change the order
this.findSteppingNo(last, first);
}
else
{
process.stdout.write("\n Stepping Number in " + first + " to " + last + " is \n");
for (var i = first; i < last; ++i)
{
if (this.isStepping(i) == true)
{
process.stdout.write("  " + i);
}
}
}
process.stdout.write("\n");
}
}

function main()
{
var obj = new SteppingNumber();
// Test Case
obj.findSteppingNo(-8, 15);
obj.findSteppingNo(1, 50);
}
main();``````

#### Output

`````` Stepping Number in -8 to 15 is
-8  -7  -6  -5  -4  -3  -2  -1  0  1  2  3  4  5  6  7  8  9  10  12

Stepping Number in 1 to 50 is
1  2  3  4  5  6  7  8  9  10  12  21  23  32  34  43  45``````
``````#   Python 3 Program
#   Stepping Numbers

class SteppingNumber :
#   Check that number is stepping number
def isStepping(self, number) :
if ((number > -10 and number < 10)) :
#   When number is single digit number
return True

n = number
if (n < 0) :
n = -number

#   Get last digit
digit1 = n % 10
digit2 = 0
n = int(n / 10)
while (n != 0) :
#   Get last digit
digit2 = n % 10
if (digit2 + 1 == digit1 or digit2 - 1 == digit1) :
n = int(n / 10)
digit1 = digit2
else :
return False

return True

#   This is handling request to find the Stepping number
def findSteppingNo(self, first, last) :
if (last < first) :
#   Change the order
self.findSteppingNo(last, first)
else :
print("\n Stepping Number in ", first ," to ", last ," is ")
i = first
while (i < last) :
if (self.isStepping(i) == True) :
print("  ", i, end = "")

i += 1

print(end = "\n")

def main() :
obj = SteppingNumber()
#  Test Case
obj.findSteppingNo(-8, 15)
obj.findSteppingNo(1, 50)

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

#### Output

`````` Stepping Number in  -8  to  15  is
-8   -7   -6   -5   -4   -3   -2   -1   0   1   2   3   4   5   6   7   8   9   10   12

Stepping Number in  1  to  50  is
1   2   3   4   5   6   7   8   9   10   12   21   23   32   34   43   45``````
``````#   Ruby Program
#   Stepping Numbers

class SteppingNumber
#   Check that number is stepping number
def isStepping(number)
if ((number > -10 && number < 10))
#   When number is single digit number
return true
end

n = number
if (n < 0)
n = -number
end

#   Get last digit
digit1 = n % 10
digit2 = 0
n = n / 10
while (n != 0)
#   Get last digit
digit2 = n % 10
if (digit2 + 1 == digit1 || digit2 - 1 == digit1)
n = n / 10
digit1 = digit2
else
return false
end

end

return true
end

#   This is handling request to find the Stepping number
def findSteppingNo(first, last)
if (last < first)
#   Change the order
self.findSteppingNo(last, first)
else
print("\n Stepping Number in ", first ," to ", last ," is \n")
i = first
while (i < last)
if (self.isStepping(i) == true)
print("  ", i)
end

i += 1
end

end

print("\n")
end

end

def main()
obj = SteppingNumber.new()
#  Test Case
obj.findSteppingNo(-8, 15)
obj.findSteppingNo(1, 50)
end

main()``````

#### Output

`````` Stepping Number in -8 to 15 is
-8  -7  -6  -5  -4  -3  -2  -1  0  1  2  3  4  5  6  7  8  9  10  12

Stepping Number in 1 to 50 is
1  2  3  4  5  6  7  8  9  10  12  21  23  32  34  43  45
``````
``````/*
Scala Program
Stepping Numbers
*/
class SteppingNumber
{
//   Check that number is stepping number
def isStepping(number: Int): Boolean = {
if ((number > -10 && number < 10))
{
//   When number is single digit number
return true;
}
var n: Int = number;
if (n < 0)
{
n = -number;
}
//   Get last digit
var digit1: Int = n % 10;
var digit2: Int = 0;
n = (n / 10).toInt;
while (n != 0)
{
//   Get last digit
digit2 = n % 10;
if (digit2 + 1 == digit1 || digit2 - 1 == digit1)
{
n = (n / 10).toInt;
digit1 = digit2;
}
else
{
return false;
}
}
return true;
}
//   This is handling request to find the Stepping number
def findSteppingNo(first: Int, last: Int): Unit = {
if (last < first)
{
//   Change the order
this.findSteppingNo(last, first);
}
else
{
print("\n Stepping Number in " + first + " to " + last + " is \n");
var i: Int = first;
while (i < last)
{
if (this.isStepping(i) == true)
{
print("  " + i);
}
i += 1;
}
}
print("\n");
}
}
object Main
{
def main(args: Array[String]): Unit = {
var obj: SteppingNumber = new SteppingNumber();
//  Test Case
obj.findSteppingNo(-8, 15);
obj.findSteppingNo(1, 50);
}
}``````

#### Output

`````` Stepping Number in -8 to 15 is
-8  -7  -6  -5  -4  -3  -2  -1  0  1  2  3  4  5  6  7  8  9  10  12

Stepping Number in 1 to 50 is
1  2  3  4  5  6  7  8  9  10  12  21  23  32  34  43  45``````
``````/*
Swift 4 Program
Stepping Numbers
*/
class SteppingNumber
{
//   Check that number is stepping number
func isStepping(_ number: Int)->Bool
{
if ((number > -10 && number < 10))
{
//   When number is single digit number
return true;
}
var n: Int = number;
if (n < 0)
{
n = -number;
}
//   Get last digit
var digit1: Int = n % 10;
var digit2: Int = 0;
n = n / 10;
while (n != 0)
{
//   Get last digit
digit2 = n % 10;
if (digit2 + 1 == digit1 || digit2 - 1 == digit1)
{
n = n / 10;
digit1 = digit2;
}
else
{
return false;
}
}
return true;
}
//   This is handling request to find the Stepping number
func findSteppingNo(_ first: Int, _ last: Int)
{
if (last < first)
{
//   Change the order
self.findSteppingNo(last, first);
}
else
{
print("\n Stepping Number in ", first ," to ", last ," is ");
var i: Int = first;
while (i < last)
{
if (self.isStepping(i) == true)
{
print("  ", i, terminator: "");
}
i += 1;
}
}
print(terminator: "\n");
}
}
func main()
{
let obj: SteppingNumber = SteppingNumber();
//  Test Case
obj.findSteppingNo(-8, 15);
obj.findSteppingNo(1, 50);
}
main();``````

#### Output

`````` Stepping Number in  -8  to  15  is
-8   -7   -6   -5   -4   -3   -2   -1   0   1   2   3   4   5   6   7   8   9   10   12

Stepping Number in  1  to  50  is
1   2   3   4   5   6   7   8   9   10   12   21   23   32   34   43   45``````
``````/*
Kotlin Program
Stepping Numbers
*/
class SteppingNumber
{
//   Check that number is stepping number
fun isStepping(number: Int): Boolean
{
if ((number > -10 && number < 10))
{
//   When number is single digit number
return true;
}
var n: Int = number;
if (n < 0)
{
n = -number;
}
//   Get last digit
var digit1: Int = n % 10;
var digit2: Int ;
n = n / 10;
while (n != 0)
{
//   Get last digit
digit2 = n % 10;
if (digit2 + 1 == digit1 || digit2 - 1 == digit1)
{
n = n / 10;
digit1 = digit2;
}
else
{
return false;
}
}
return true;
}
//   This is handling request to find the Stepping number
fun findSteppingNo(first: Int, last: Int): Unit
{
if (last < first)
{
//   Change the order
this.findSteppingNo(last, first);
}
else
{
print("\n Stepping Number in " + first + " to " + last + " is \n");
var i: Int = first;
while (i < last)
{
if (this.isStepping(i) == true)
{
print("  " + i);
}
i += 1;
}
}
print("\n");
}
}
fun main(args: Array<String>): Unit
{
var obj: SteppingNumber = SteppingNumber();
//  Test Case
obj.findSteppingNo(-8, 15);
obj.findSteppingNo(1, 50);
}``````

#### Output

`````` Stepping Number in -8 to 15 is
-8  -7  -6  -5  -4  -3  -2  -1  0  1  2  3  4  5  6  7  8  9  10  12

Stepping Number in 1 to 50 is
1  2  3  4  5  6  7  8  9  10  12  21  23  32  34  43  45``````
``````// Rust program
// Stepping Numbers

fn main()
{
//Test Case
find_stepping_no(-8, 15);
find_stepping_no(1, 50);
}

fn find_stepping_no(first: i32, last: i32)
{
if last < first
{
// Change the order
find_stepping_no(last, first);
}
else
{
print!("\n Stepping Number in {} to {} is \n", first, last);
let mut i: i32 = first;
while i < last
{
if is_stepping(i) == 1
{
print!("  {}", i);
}
i += 1;
}
}
print!("\n");
}
fn is_stepping(number: i32) -> i32
{
if  number > -10 && number < 10
{
// When number is single digit number
return 1;
}
let mut n: i32 = number;
if n < 0
{
n = -number;
}
// Get last digit
let mut digit1: i32 = n % 10;
let mut digit2: i32  ;
n = n / 10;
while n != 0
{
// Get last digit
digit2 = n % 10;
if digit2 + 1 == digit1 || digit2 - 1 == digit1
{
n = n / 10;
digit1 = digit2;
}
else
{
return 0;
}
}
return 1;
}``````

#### Output

`````` Stepping Number in -8 to 15 is
-8  -7  -6  -5  -4  -3  -2  -1  0  1  2  3  4  5  6  7  8  9  10  12

Stepping Number in 1 to 50 is
1  2  3  4  5  6  7  8  9  10  12  21  23  32  34  43  45``````

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