Split a large Odd number into small Odd number

Here given code implementation process.

// C program for
// Split a large Odd number into small Odd number
#include <stdio.h>
#include <string.h>

// Check whether given character is form of odd or not
int isOddDigit(char ch)
{
    if (ch == '1' || ch == '3' || ch == '5' || 
        ch == '7' || ch == '9')
    {
        // Yes
        return 1;
    }
    // No
    return 0;
}
void partition(char *num, char result[], 
  int index, int position, int k)
{
    if (position == k)
    {
        // Display calculated result
        result[index] = '\0';
        printf("\n %s", result);
        return;
    }
    int count = 0;
    for (int i = position; i < k; ++i)
    {
        result[index + count] = num[i];
        if (isOddDigit(num[i]) == 1)
        {
            result[index + count + 1] = ' ';
            // Find next odd number
            partition(num, result, index + count + 2, i + 1, k);
        }
        count++;
    }
}
void splitIntoOddNumber(char *num)
{
    int k = strlen(num);
    if (k == 0 || !isOddDigit(num[k - 1]))
    {
        return;
    }
    // Collects the results digits
    char result[(k *2) + 1];
    printf("\n Given number : %s", num);
    partition(num, result, 0, 0, k);
}
int main()
{
    // Test 
    splitIntoOddNumber("15203456739");
    return 0;
}

Output

 Given number : 15203456739
 1 5 203 45 67 3 9
 1 5 203 45 67 39
 1 5 203 45 673 9
 1 5 203 45 6739
 1 5 203 4567 3 9
 1 5 203 4567 39
 1 5 203 45673 9
 1 5 203 456739
 1 5 20345 67 3 9
 1 5 20345 67 39
 1 5 20345 673 9
 1 5 20345 6739
 1 5 2034567 3 9
 1 5 2034567 39
 1 5 20345673 9
 1 5 203456739
 1 5203 45 67 3 9
 1 5203 45 67 39
 1 5203 45 673 9
 1 5203 45 6739
 1 5203 4567 3 9
 1 5203 4567 39
 1 5203 45673 9
 1 5203 456739
 1 520345 67 3 9
 1 520345 67 39
 1 520345 673 9
 1 520345 6739
 1 52034567 3 9
 1 52034567 39
 1 520345673 9
 1 5203456739
 15 203 45 67 3 9
 15 203 45 67 39
 15 203 45 673 9
 15 203 45 6739
 15 203 4567 3 9
 15 203 4567 39
 15 203 45673 9
 15 203 456739
 15 20345 67 3 9
 15 20345 67 39
 15 20345 673 9
 15 20345 6739
 15 2034567 3 9
 15 2034567 39
 15 20345673 9
 15 203456739
 15203 45 67 3 9
 15203 45 67 39
 15203 45 673 9
 15203 45 6739
 15203 4567 3 9
 15203 4567 39
 15203 45673 9
 15203 456739
 1520345 67 3 9
 1520345 67 39
 1520345 673 9
 1520345 6739
 152034567 3 9
 152034567 39
 1520345673 9
 15203456739
/*
    Java program
    Split a large Odd number into small Odd number
*/
public class Splitting
{
	// Check whether given character is form of odd or not
	public boolean isOddDigit(char ch)
	{
		if (ch == '1' || ch == '3' || ch == '5' || 
			ch == '7' || ch == '9')
		{
			// Yes
			return true;
		}
		// No
		return false;
	}
	   public void displayResult(char[] result, int n)
    {
        for (int i = 0; i < n; ++i)
        {
            System.out.print(result[i]);
        }
        System.out.print("\n");
    }
	public void partition(String num, char[] result, 
      int index, int position, int k)
	{
		if (position == k)
		{
			// Display calculated result
			displayResult(result, index);
            return;
		}
		int count = 0;
		for (int i = position; i < k; ++i)
		{
			// Collect element value
			result[index + count] = num.charAt(i);

			if (isOddDigit(num.charAt(i)))
			{
				result[index + count + 1] = ' ';
				// Find next odd number
				partition(num, result, index + count + 2, i + 1, k);
			}
			count++;
		}
	}
	public void splitIntoOddNumber(String num)
	{
		int k = num.length();
		if (k == 0 || !isOddDigit(num.charAt(k - 1)))
		{
			return;
		}
		// Collects the results digits
		char[] result = new char[(k * 2) + 1];
		System.out.println("\n Given number : " + num );
		partition(num, result, 0, 0, k);
	}
	public static void main(String[] args)
	{
		Splitting task = new Splitting();
		// Test 
		task.splitIntoOddNumber("15203456739");

	}
}

Output

 Given number : 15203456739
1 5 203 45 67 3 9
1 5 203 45 67 39
1 5 203 45 673 9
1 5 203 45 6739
1 5 203 4567 3 9
1 5 203 4567 39
1 5 203 45673 9
1 5 203 456739
1 5 20345 67 3 9
1 5 20345 67 39
1 5 20345 673 9
1 5 20345 6739
1 5 2034567 3 9
1 5 2034567 39
1 5 20345673 9
1 5 203456739
1 5203 45 67 3 9
1 5203 45 67 39
1 5203 45 673 9
1 5203 45 6739
1 5203 4567 3 9
1 5203 4567 39
1 5203 45673 9
1 5203 456739
1 520345 67 3 9
1 520345 67 39
1 520345 673 9
1 520345 6739
1 52034567 3 9
1 52034567 39
1 520345673 9
1 5203456739
15 203 45 67 3 9
15 203 45 67 39
15 203 45 673 9
15 203 45 6739
15 203 4567 3 9
15 203 4567 39
15 203 45673 9
15 203 456739
15 20345 67 3 9
15 20345 67 39
15 20345 673 9
15 20345 6739
15 2034567 3 9
15 2034567 39
15 20345673 9
15 203456739
15203 45 67 3 9
15203 45 67 39
15203 45 673 9
15203 45 6739
15203 4567 3 9
15203 4567 39
15203 45673 9
15203 456739
1520345 67 3 9
1520345 67 39
1520345 673 9
1520345 6739
152034567 3 9
152034567 39
1520345673 9
15203456739
// Include header file
#include <iostream>
#include <string>

using namespace std;
/*
    C++ program
    Split a large Odd number into small Odd number
*/
class Splitting
{
	public:
		// Check whether given character is form of odd or not
		bool isOddDigit(char ch)
		{
			if (ch == '1' || ch == '3' || ch == '5' || 
                ch == '7' || ch == '9')
			{
				// Yes
				return true;
			}
			// No
			return false;
		}
	void displayResult(char result[], int n)
	{
		for (int i = 0; i < n; ++i)
		{
			cout << result[i];
		}
		cout << "\n";
	}
	void partition(string num, char result[], 
      int index, int position, int k)
	{
		if (position == k)
		{
			// Display calculated result
			this->displayResult(result, index);
			return;
		}
		int count = 0;
		for (int i = position; i < k; ++i)
		{
			// Collect element value
			result[index + count] = num[i];
			if (this->isOddDigit(num[i]))
			{
				result[index + count + 1] = ' ';
				// Find next odd number
				this->partition(num, result, 
                                index + count + 2, i + 1, k);
			}
			count++;
		}
	}
	void splitIntoOddNumber(string num)
	{
		int k = num.length();
		if (k == 0 || !this->isOddDigit(num[k - 1]))
		{
			return;
		}
		// Collects the results digits
		char result[(k *2) + 1];
		cout << "\n Given number : " << num << endl;
		this->partition(num, result, 0, 0, k);
	}
};
int main()
{
	Splitting *task = new Splitting();
	// Test 
	task->splitIntoOddNumber("15203456739");
	return 0;
}

Output

 Given number : 15203456739
1 5 203 45 67 3 9
1 5 203 45 67 39
1 5 203 45 673 9
1 5 203 45 6739
1 5 203 4567 3 9
1 5 203 4567 39
1 5 203 45673 9
1 5 203 456739
1 5 20345 67 3 9
1 5 20345 67 39
1 5 20345 673 9
1 5 20345 6739
1 5 2034567 3 9
1 5 2034567 39
1 5 20345673 9
1 5 203456739
1 5203 45 67 3 9
1 5203 45 67 39
1 5203 45 673 9
1 5203 45 6739
1 5203 4567 3 9
1 5203 4567 39
1 5203 45673 9
1 5203 456739
1 520345 67 3 9
1 520345 67 39
1 520345 673 9
1 520345 6739
1 52034567 3 9
1 52034567 39
1 520345673 9
1 5203456739
15 203 45 67 3 9
15 203 45 67 39
15 203 45 673 9
15 203 45 6739
15 203 4567 3 9
15 203 4567 39
15 203 45673 9
15 203 456739
15 20345 67 3 9
15 20345 67 39
15 20345 673 9
15 20345 6739
15 2034567 3 9
15 2034567 39
15 20345673 9
15 203456739
15203 45 67 3 9
15203 45 67 39
15203 45 673 9
15203 45 6739
15203 4567 3 9
15203 4567 39
15203 45673 9
15203 456739
1520345 67 3 9
1520345 67 39
1520345 673 9
1520345 6739
152034567 3 9
152034567 39
1520345673 9
15203456739
// Include namespace system
using System;
/*
    Csharp program
    Split a large Odd number into small Odd number
*/
public class Splitting
{
	// Check whether given character is form of odd or not
	public Boolean isOddDigit(char ch)
	{
		if (ch == '1' || ch == '3' || ch == '5' || 
            ch == '7' || ch == '9')
		{
			// Yes
			return true;
		}
		// No
		return false;
	}
	public void displayResult(char[] result, int n)
	{
		for (int i = 0; i < n; ++i)
		{
			Console.Write(result[i]);
		}
		Console.Write("\n");
	}
	public void partition(String num, char[] result, 
      int index, int position, int k)
	{
		if (position == k)
		{
			// Display calculated result
			this.displayResult(result, index);
			return;
		}
		int count = 0;
		for (int i = position; i < k; ++i)
		{
			// Collect element value
			result[index + count] = num[i];
			if (this.isOddDigit(num[i]))
			{
				result[index + count + 1] = ' ';
				// Find next odd number
				this.partition(num, result, index + count + 2, i + 1, k);
			}
			count++;
		}
	}
	public void splitIntoOddNumber(String num)
	{
		int k = num.Length;
		if (k == 0 || !this.isOddDigit(num[k - 1]))
		{
			return;
		}
		// Collects the results digits
		char[] result = new char[(k * 2) + 1];
		Console.WriteLine("\n Given number : " + num);
		this.partition(num, result, 0, 0, k);
	}
	public static void Main(String[] args)
	{
		Splitting task = new Splitting();
		// Test 
		task.splitIntoOddNumber("15203456739");
	}
}

Output

 Given number : 15203456739
1 5 203 45 67 3 9
1 5 203 45 67 39
1 5 203 45 673 9
1 5 203 45 6739
1 5 203 4567 3 9
1 5 203 4567 39
1 5 203 45673 9
1 5 203 456739
1 5 20345 67 3 9
1 5 20345 67 39
1 5 20345 673 9
1 5 20345 6739
1 5 2034567 3 9
1 5 2034567 39
1 5 20345673 9
1 5 203456739
1 5203 45 67 3 9
1 5203 45 67 39
1 5203 45 673 9
1 5203 45 6739
1 5203 4567 3 9
1 5203 4567 39
1 5203 45673 9
1 5203 456739
1 520345 67 3 9
1 520345 67 39
1 520345 673 9
1 520345 6739
1 52034567 3 9
1 52034567 39
1 520345673 9
1 5203456739
15 203 45 67 3 9
15 203 45 67 39
15 203 45 673 9
15 203 45 6739
15 203 4567 3 9
15 203 4567 39
15 203 45673 9
15 203 456739
15 20345 67 3 9
15 20345 67 39
15 20345 673 9
15 20345 6739
15 2034567 3 9
15 2034567 39
15 20345673 9
15 203456739
15203 45 67 3 9
15203 45 67 39
15203 45 673 9
15203 45 6739
15203 4567 3 9
15203 4567 39
15203 45673 9
15203 456739
1520345 67 3 9
1520345 67 39
1520345 673 9
1520345 6739
152034567 3 9
152034567 39
1520345673 9
15203456739
package main
import "fmt"
/*
    Go program
    Split a large Odd number into small Odd number
*/
type Splitting struct {}
func getSplitting() * Splitting {
	var me *Splitting = &Splitting {}
	return me
}
// Check whether given character is form of odd or not
func(this Splitting) isOddDigit(ch byte) bool {
	if ch == '1' || ch == '3' || ch == '5' || 
      ch == '7' || ch == '9' {
		// Yes
		return true
	}
	// No
	return false
}
func(this Splitting) displayResult(result[] byte, n int) {
	for i := 0 ; i < n ; i++ {
		fmt.Printf("%c",result[i])
	}
	fmt.Print("\n")
}
func(this Splitting) partition(num string, result[] byte, 
  index int, position int, k int) {
	if position == k {
		// Display calculated result
		this.displayResult(result, index)
		return
	}
	var count int = 0
	for i := position ; i < k ; i++ {
		// Collect element value
		result[index + count] = num[i]
		if this.isOddDigit(num[i]) {
			result[index + count + 1] = ' '
			// Find next odd number
			this.partition(num, result, index + count + 2, i + 1, k)
		}
		count++
	}
}
func(this Splitting) splitIntoOddNumber(num string) {
	var k int = len(num)
	if k == 0 || !this.isOddDigit(num[k - 1]) {
		return
	}
	// Collects the results digits
	var result = make([] byte, (k * 2) + 1)
	fmt.Println("\n Given number : ", num)
	this.partition(num, result, 0, 0, k)
}
func main() {
	var task * Splitting = getSplitting()
	// Test 
	task.splitIntoOddNumber("15203456739")
}

Output

 Given number : 15203456739
1 5 203 45 67 3 9
1 5 203 45 67 39
1 5 203 45 673 9
1 5 203 45 6739
1 5 203 4567 3 9
1 5 203 4567 39
1 5 203 45673 9
1 5 203 456739
1 5 20345 67 3 9
1 5 20345 67 39
1 5 20345 673 9
1 5 20345 6739
1 5 2034567 3 9
1 5 2034567 39
1 5 20345673 9
1 5 203456739
1 5203 45 67 3 9
1 5203 45 67 39
1 5203 45 673 9
1 5203 45 6739
1 5203 4567 3 9
1 5203 4567 39
1 5203 45673 9
1 5203 456739
1 520345 67 3 9
1 520345 67 39
1 520345 673 9
1 520345 6739
1 52034567 3 9
1 52034567 39
1 520345673 9
1 5203456739
15 203 45 67 3 9
15 203 45 67 39
15 203 45 673 9
15 203 45 6739
15 203 4567 3 9
15 203 4567 39
15 203 45673 9
15 203 456739
15 20345 67 3 9
15 20345 67 39
15 20345 673 9
15 20345 6739
15 2034567 3 9
15 2034567 39
15 20345673 9
15 203456739
15203 45 67 3 9
15203 45 67 39
15203 45 673 9
15203 45 6739
15203 4567 3 9
15203 4567 39
15203 45673 9
15203 456739
1520345 67 3 9
1520345 67 39
1520345 673 9
1520345 6739
152034567 3 9
152034567 39
1520345673 9
15203456739
<?php
/*
    Php program
    Split a large Odd number into small Odd number
*/
class Splitting
{
	// Check whether given character is form of odd or not
	public	function isOddDigit($ch)
	{
		if ($ch == '1' || $ch == '3' || $ch == '5' || 
            $ch == '7' || $ch == '9')
		{
			// Yes
			return true;
		}
		// No
		return false;
	}
	public	function displayResult($result, $n)
	{
		for ($i = 0; $i < $n; ++$i)
		{
			echo($result[$i]);
		}
		echo("\n");
	}
	public	function partition($num, $result, 
                                $index, $position, $k)
	{
		if ($position == $k)
		{
			// Display calculated result
			$this->displayResult($result, $index);
			return;
		}
		$count = 0;
		for ($i = $position; $i < $k; ++$i)
		{
			// Collect element value
			$result[$index + $count] = $num[$i];
			if ($this->isOddDigit($num[$i]))
			{
				$result[$index + $count + 1] = ' ';
				// Find next odd number
				$this->partition($num, $result, 
                                 $index + $count + 2, $i + 1, $k);
			}
			$count++;
		}
	}
	public	function splitIntoOddNumber($num)
	{
		$k = strlen($num);
		if ($k == 0 || !$this->isOddDigit($num[$k - 1]))
		{
			return;
		}
		// Collects the results digits
		$result = array_fill(0, ($k * 2) + 1, ' ');
		echo("\n Given number : ".$num.
			"\n");
		$this->partition($num, $result, 0, 0, $k);
	}
}

function main()
{
	$task = new Splitting();
	// Test 
	$task->splitIntoOddNumber("15203456739");
}
main();

Output

 Given number : 15203456739
1 5 203 45 67 3 9
1 5 203 45 67 39
1 5 203 45 673 9
1 5 203 45 6739
1 5 203 4567 3 9
1 5 203 4567 39
1 5 203 45673 9
1 5 203 456739
1 5 20345 67 3 9
1 5 20345 67 39
1 5 20345 673 9
1 5 20345 6739
1 5 2034567 3 9
1 5 2034567 39
1 5 20345673 9
1 5 203456739
1 5203 45 67 3 9
1 5203 45 67 39
1 5203 45 673 9
1 5203 45 6739
1 5203 4567 3 9
1 5203 4567 39
1 5203 45673 9
1 5203 456739
1 520345 67 3 9
1 520345 67 39
1 520345 673 9
1 520345 6739
1 52034567 3 9
1 52034567 39
1 520345673 9
1 5203456739
15 203 45 67 3 9
15 203 45 67 39
15 203 45 673 9
15 203 45 6739
15 203 4567 3 9
15 203 4567 39
15 203 45673 9
15 203 456739
15 20345 67 3 9
15 20345 67 39
15 20345 673 9
15 20345 6739
15 2034567 3 9
15 2034567 39
15 20345673 9
15 203456739
15203 45 67 3 9
15203 45 67 39
15203 45 673 9
15203 45 6739
15203 4567 3 9
15203 4567 39
15203 45673 9
15203 456739
1520345 67 3 9
1520345 67 39
1520345 673 9
1520345 6739
152034567 3 9
152034567 39
1520345673 9
15203456739
/*
    Node JS program
    Split a large Odd number into small Odd number
*/
class Splitting
{
	// Check whether given character is form of odd or not
	isOddDigit(ch)
	{
		if (ch == '1' || ch == '3' || ch == '5' || 
            ch == '7' || ch == '9')
		{
			// Yes
			return true;
		}
		// No
		return false;
	}
	displayResult(result, n)
	{
		for (var i = 0; i < n; ++i)
		{
			process.stdout.write(result[i]);
		}
		process.stdout.write("\n");
	}
	partition(num, result, index, position, k)
	{
		if (position == k)
		{
			// Display calculated result
			this.displayResult(result, index);
			return;
		}
		var count = 0;
		for (var i = position; i < k; ++i)
		{
			// Collect element value
			result[index + count] = num.charAt(i);
			if (this.isOddDigit(num.charAt(i)))
			{
				result[index + count + 1] = ' ';
				// Find next odd number
				this.partition(num, result, 
                               index + count + 2, i + 1, k);
			}
			count++;
		}
	}
	splitIntoOddNumber(num)
	{
		var k = num.length;
		if (k == 0 || !this.isOddDigit(num.charAt(k - 1)))
		{
			return;
		}
		// Collects the results digits
		var result = Array((k * 2) + 1).fill(' ');
		console.log("\n Given number : " + num);
		this.partition(num, result, 0, 0, k);
	}
}

function main()
{
	var task = new Splitting();
	// Test 
	task.splitIntoOddNumber("15203456739");
}
main();

Output

 Given number : 15203456739
1 5 203 45 67 3 9
1 5 203 45 67 39
1 5 203 45 673 9
1 5 203 45 6739
1 5 203 4567 3 9
1 5 203 4567 39
1 5 203 45673 9
1 5 203 456739
1 5 20345 67 3 9
1 5 20345 67 39
1 5 20345 673 9
1 5 20345 6739
1 5 2034567 3 9
1 5 2034567 39
1 5 20345673 9
1 5 203456739
1 5203 45 67 3 9
1 5203 45 67 39
1 5203 45 673 9
1 5203 45 6739
1 5203 4567 3 9
1 5203 4567 39
1 5203 45673 9
1 5203 456739
1 520345 67 3 9
1 520345 67 39
1 520345 673 9
1 520345 6739
1 52034567 3 9
1 52034567 39
1 520345673 9
1 5203456739
15 203 45 67 3 9
15 203 45 67 39
15 203 45 673 9
15 203 45 6739
15 203 4567 3 9
15 203 4567 39
15 203 45673 9
15 203 456739
15 20345 67 3 9
15 20345 67 39
15 20345 673 9
15 20345 6739
15 2034567 3 9
15 2034567 39
15 20345673 9
15 203456739
15203 45 67 3 9
15203 45 67 39
15203 45 673 9
15203 45 6739
15203 4567 3 9
15203 4567 39
15203 45673 9
15203 456739
1520345 67 3 9
1520345 67 39
1520345 673 9
1520345 6739
152034567 3 9
152034567 39
1520345673 9
15203456739
#    Python 3 program
#    Split a large Odd number into small Odd number
class Splitting :
	#  Check whether given character is form of odd or not
	def isOddDigit(self, ch) :
		if (ch == '1'
			or ch == '3'
			or ch == '5'
			or ch == '7'
			or ch == '9') :
			#  Yes
			return True
		
		#  No
		return False
	
	def displayResult(self, result, n) :
		i = 0
		while (i < n) :
			print(result[i], end = "")
			i += 1
		
		print(end = "\n")
	
	def partition(self, num, result, index, position, k) :
		if (position == k) :
			#  Display calculated result
			self.displayResult(result, index)
			return
		
		count = 0
		i = position
		while (i < k) :
			#  Collect element value
			result[index + count] = num[i]
			if (self.isOddDigit(num[i])) :
				result[index + count + 1] = ' '
				#  Find next odd number
				self.partition(num, result, 
                               index + count + 2, i + 1, k)
			
			count += 1
			i += 1
		
	
	def splitIntoOddNumber(self, num) :
		k = len(num)
		if (k == 0 or not self.isOddDigit(num[k - 1])) :
			return
		
		#  Collects the results digits
		result = [ ' '
		] * ((k * 2) + 1)
		print("\n Given number : ", num)
		self.partition(num, result, 0, 0, k)
	

def main() :
	task = Splitting()
	#  Test 
	task.splitIntoOddNumber("15203456739")

if __name__ == "__main__": main()

Output

 Given number :  15203456739
1 5 203 45 67 3 9
1 5 203 45 67 39
1 5 203 45 673 9
1 5 203 45 6739
1 5 203 4567 3 9
1 5 203 4567 39
1 5 203 45673 9
1 5 203 456739
1 5 20345 67 3 9
1 5 20345 67 39
1 5 20345 673 9
1 5 20345 6739
1 5 2034567 3 9
1 5 2034567 39
1 5 20345673 9
1 5 203456739
1 5203 45 67 3 9
1 5203 45 67 39
1 5203 45 673 9
1 5203 45 6739
1 5203 4567 3 9
1 5203 4567 39
1 5203 45673 9
1 5203 456739
1 520345 67 3 9
1 520345 67 39
1 520345 673 9
1 520345 6739
1 52034567 3 9
1 52034567 39
1 520345673 9
1 5203456739
15 203 45 67 3 9
15 203 45 67 39
15 203 45 673 9
15 203 45 6739
15 203 4567 3 9
15 203 4567 39
15 203 45673 9
15 203 456739
15 20345 67 3 9
15 20345 67 39
15 20345 673 9
15 20345 6739
15 2034567 3 9
15 2034567 39
15 20345673 9
15 203456739
15203 45 67 3 9
15203 45 67 39
15203 45 673 9
15203 45 6739
15203 4567 3 9
15203 4567 39
15203 45673 9
15203 456739
1520345 67 3 9
1520345 67 39
1520345 673 9
1520345 6739
152034567 3 9
152034567 39
1520345673 9
15203456739
#    Ruby program
#    Split a large Odd number into small Odd number
class Splitting 
	#  Check whether given character is form of odd or not
	def isOddDigit(ch) 
		if (ch == '1' || ch == '3' || ch == '5' || 
            ch == '7' || ch == '9') 
			#  Yes
			return true
		end

		#  No
		return false
	end

	def displayResult(result, n) 
		i = 0
		while (i < n) 
			print(result[i])
			i += 1
		end

		print("\n")
	end

	def partition(num, result, index, position, k) 
		if (position == k) 
			#  Display calculated result
			self.displayResult(result, index)
			return
		end

		count = 0
		i = position
		while (i < k) 
			#  Collect element value
			result[index + count] = num[i]
			if (self.isOddDigit(num[i])) 
				result[index + count + 1] = ' '
				#  Find next odd number
				self.partition(num, result, index + count + 2, i + 1, k)
			end

			count += 1
			i += 1
		end

	end

	def splitIntoOddNumber(num) 
		k = num.length
		if (k == 0 || !self.isOddDigit(num[k - 1])) 
			return
		end

		#  Collects the results digits
		result = Array.new((k * 2) + 1) { ' '
		}
		print("\n Given number : ", num, "\n")
		self.partition(num, result, 0, 0, k)
	end

end

def main() 
	task = Splitting.new()
	#  Test 
	task.splitIntoOddNumber("15203456739")
end

main()

Output

 Given number : 15203456739
1 5 203 45 67 3 9 
1 5 203 45 67 39 
1 5 203 45 673 9 
1 5 203 45 6739 
1 5 203 4567 3 9 
1 5 203 4567 39 
1 5 203 45673 9 
1 5 203 456739 
1 5 20345 67 3 9 
1 5 20345 67 39 
1 5 20345 673 9 
1 5 20345 6739 
1 5 2034567 3 9 
1 5 2034567 39 
1 5 20345673 9 
1 5 203456739 
1 5203 45 67 3 9 
1 5203 45 67 39 
1 5203 45 673 9 
1 5203 45 6739 
1 5203 4567 3 9 
1 5203 4567 39 
1 5203 45673 9 
1 5203 456739 
1 520345 67 3 9 
1 520345 67 39 
1 520345 673 9 
1 520345 6739 
1 52034567 3 9 
1 52034567 39 
1 520345673 9 
1 5203456739 
15 203 45 67 3 9 
15 203 45 67 39 
15 203 45 673 9 
15 203 45 6739 
15 203 4567 3 9 
15 203 4567 39 
15 203 45673 9 
15 203 456739 
15 20345 67 3 9 
15 20345 67 39 
15 20345 673 9 
15 20345 6739 
15 2034567 3 9 
15 2034567 39 
15 20345673 9 
15 203456739 
15203 45 67 3 9 
15203 45 67 39 
15203 45 673 9 
15203 45 6739 
15203 4567 3 9 
15203 4567 39 
15203 45673 9 
15203 456739 
1520345 67 3 9 
1520345 67 39 
1520345 673 9 
1520345 6739 
152034567 3 9 
152034567 39 
1520345673 9 
15203456739 
import scala.collection.mutable._;
/*
    Scala program
    Split a large Odd number into small Odd number
*/
class Splitting()
{
	// Check whether given character is form of odd or not
	def isOddDigit(ch: Char): Boolean = {
		if (ch == '1' || ch == '3' || ch == '5' || 
             ch == '7' || ch == '9')
		{
			// Yes
			return true;
		}
		// No
		return false;
	}
	def displayResult(result: Array[Char], n: Int): Unit = {
		var i: Int = 0;
		while (i < n)
		{
			print(result(i));
			i += 1;
		}
		print("\n");
	}
	def partition(num: String, result: Array[Char], index: Int, 
      position: Int, k: Int): Unit = {
		if (position == k)
		{
			// Display calculated result
			displayResult(result, index);
			return;
		}
		var count: Int = 0;
		var i: Int = position;
		while (i < k)
		{
			// Collect element value
			result(index + count) = num.charAt(i);
			if (isOddDigit(num.charAt(i)))
			{
				result(index + count + 1) = ' ';
				// Find next odd number
				partition(num, result, index + count + 2, i + 1, k);
			}
			count += 1;
			i += 1;
		}
	}
	def splitIntoOddNumber(num: String): Unit = {
		var k: Int = num.length();
		if (k == 0 || !isOddDigit(num.charAt(k - 1)))
		{
			return;
		}
		// Collects the results digits
		var result: Array[Char] = Array.fill[Char]((k * 2) + 1)(' ');
		println("\n Given number : " + num);
		partition(num, result, 0, 0, k);
	}
}
object Main
{
	def main(args: Array[String]): Unit = {
		var task: Splitting = new Splitting();
		// Test 
		task.splitIntoOddNumber("15203456739");
	}
}

Output

 Given number : 15203456739
1 5 203 45 67 3 9
1 5 203 45 67 39
1 5 203 45 673 9
1 5 203 45 6739
1 5 203 4567 3 9
1 5 203 4567 39
1 5 203 45673 9
1 5 203 456739
1 5 20345 67 3 9
1 5 20345 67 39
1 5 20345 673 9
1 5 20345 6739
1 5 2034567 3 9
1 5 2034567 39
1 5 20345673 9
1 5 203456739
1 5203 45 67 3 9
1 5203 45 67 39
1 5203 45 673 9
1 5203 45 6739
1 5203 4567 3 9
1 5203 4567 39
1 5203 45673 9
1 5203 456739
1 520345 67 3 9
1 520345 67 39
1 520345 673 9
1 520345 6739
1 52034567 3 9
1 52034567 39
1 520345673 9
1 5203456739
15 203 45 67 3 9
15 203 45 67 39
15 203 45 673 9
15 203 45 6739
15 203 4567 3 9
15 203 4567 39
15 203 45673 9
15 203 456739
15 20345 67 3 9
15 20345 67 39
15 20345 673 9
15 20345 6739
15 2034567 3 9
15 2034567 39
15 20345673 9
15 203456739
15203 45 67 3 9
15203 45 67 39
15203 45 673 9
15203 45 6739
15203 4567 3 9
15203 4567 39
15203 45673 9
15203 456739
1520345 67 3 9
1520345 67 39
1520345 673 9
1520345 6739
152034567 3 9
152034567 39
1520345673 9
15203456739
import Foundation;
/*
    Swift 4 program
    Split a large Odd number into small Odd number
*/
class Splitting
{
	// Check whether given character is form of odd or not
	func isOddDigit(_ ch: Character) -> Bool
	{
		if (ch == "1" || ch == "3" || ch == "5" || 
            ch == "7" || ch == "9")
		{
			// Yes
			return true;
		}
		// No
		return false;
	}
	func displayResult(_ result: [Character], _ n: Int)
	{
		var i: Int = 0;
		while (i < n)
		{
			print(result[i], terminator: "");
			i += 1;
		}
		print(terminator: "\n");
	}
	func partition(_ num: [Character], 
                   _ result: inout[Character], 
      			   _ index: Int, 
                   _ position: Int, _ k: Int)
	{
		if (position == k)
		{
			// Display calculated result
			self.displayResult(result, index);
			return;
		}
		var count: Int = 0;
		var i: Int = position;
		while (i < k)
		{
			// Collect element value
			result[index + count] = num[i];
			if (self.isOddDigit(num[i]))
			{
				result[index + count + 1] = " ";
				// Find next odd number
				self.partition(num, &result, index + count + 2, i + 1, k);
			}
			count += 1;
			i += 1;
		}
	}
	func splitIntoOddNumber(_ number: String)
	{
      	let num = Array(number);
		let k: Int = num.count;
		if (k == 0 || !self.isOddDigit(num[k - 1]))
		{
			return;
		}
		// Collects the results digits
		var result: [Character] = Array(repeating: " ", count: (k * 2) + 1);
		print("\n Given number : ", number);
		self.partition(num, &result, 0, 0, k);
	}
}
func main()
{
	let task: Splitting = Splitting();
	// Test 
	task.splitIntoOddNumber("15203456739");
}
main();

Output

 Given number :  15203456739
1 5 203 45 67 3 9
1 5 203 45 67 39
1 5 203 45 673 9
1 5 203 45 6739
1 5 203 4567 3 9
1 5 203 4567 39
1 5 203 45673 9
1 5 203 456739
1 5 20345 67 3 9
1 5 20345 67 39
1 5 20345 673 9
1 5 20345 6739
1 5 2034567 3 9
1 5 2034567 39
1 5 20345673 9
1 5 203456739
1 5203 45 67 3 9
1 5203 45 67 39
1 5203 45 673 9
1 5203 45 6739
1 5203 4567 3 9
1 5203 4567 39
1 5203 45673 9
1 5203 456739
1 520345 67 3 9
1 520345 67 39
1 520345 673 9
1 520345 6739
1 52034567 3 9
1 52034567 39
1 520345673 9
1 5203456739
15 203 45 67 3 9
15 203 45 67 39
15 203 45 673 9
15 203 45 6739
15 203 4567 3 9
15 203 4567 39
15 203 45673 9
15 203 456739
15 20345 67 3 9
15 20345 67 39
15 20345 673 9
15 20345 6739
15 2034567 3 9
15 2034567 39
15 20345673 9
15 203456739
15203 45 67 3 9
15203 45 67 39
15203 45 673 9
15203 45 6739
15203 4567 3 9
15203 4567 39
15203 45673 9
15203 456739
1520345 67 3 9
1520345 67 39
1520345 673 9
1520345 6739
152034567 3 9
152034567 39
1520345673 9
15203456739
/*
    Kotlin program
    Split a large Odd number into small Odd number
*/
class Splitting
{
	// Check whether given character is form of odd or not
	fun isOddDigit(ch: Char): Boolean
	{
		if (ch == '1' || ch == '3' || ch == '5' || 
            ch == '7' || ch == '9')
		{
			// Yes
			return true;
		}
		// No
		return false;
	}
	fun displayResult(result: Array < Char > , n: Int): Unit
	{
		var i: Int = 0;
		while (i < n)
		{
			print(result[i]);
			i += 1;
		}
		print("\n");
	}
	fun partition(num: String, result: Array < Char > , 
                  index: Int, position: Int, k: Int): Unit
	{
		if (position == k)
		{
			// Display calculated result
			this.displayResult(result, index);
			return;
		}
		var count: Int = 0;
		var i: Int = position;
		while (i < k)
		{
			// Collect element value
			result[index + count] = num.get(i);
			if (this.isOddDigit(num.get(i)))
			{
				result[index + count + 1] = ' ';
				// Find next odd number
				this.partition(num, result, 
                               index + count + 2, i + 1, k);
			}
			count += 1;
			i += 1;
		}
	}
	fun splitIntoOddNumber(num: String): Unit
	{
		val k: Int = num.length;
		if (k == 0 || !this.isOddDigit(num.get(k - 1)))
		{
			return;
		}
		// Collects the results digits
		var result: Array < Char > = Array((k * 2) + 1)
		{
			' '
		};
		println("\n Given number : " + num);
		this.partition(num, result, 0, 0, k);
	}
}
fun main(args: Array < String > ): Unit
{
	val task: Splitting = Splitting();
	// Test 
	task.splitIntoOddNumber("15203456739");
}

Output

 Given number : 15203456739
1 5 203 45 67 3 9
1 5 203 45 67 39
1 5 203 45 673 9
1 5 203 45 6739
1 5 203 4567 3 9
1 5 203 4567 39
1 5 203 45673 9
1 5 203 456739
1 5 20345 67 3 9
1 5 20345 67 39
1 5 20345 673 9
1 5 20345 6739
1 5 2034567 3 9
1 5 2034567 39
1 5 20345673 9
1 5 203456739
1 5203 45 67 3 9
1 5203 45 67 39
1 5203 45 673 9
1 5203 45 6739
1 5203 4567 3 9
1 5203 4567 39
1 5203 45673 9
1 5203 456739
1 520345 67 3 9
1 520345 67 39
1 520345 673 9
1 520345 6739
1 52034567 3 9
1 52034567 39
1 520345673 9
1 5203456739
15 203 45 67 3 9
15 203 45 67 39
15 203 45 673 9
15 203 45 6739
15 203 4567 3 9
15 203 4567 39
15 203 45673 9
15 203 456739
15 20345 67 3 9
15 20345 67 39
15 20345 673 9
15 20345 6739
15 2034567 3 9
15 2034567 39
15 20345673 9
15 203456739
15203 45 67 3 9
15203 45 67 39
15203 45 673 9
15203 45 6739
15203 4567 3 9
15203 4567 39
15203 45673 9
15203 456739
1520345 67 3 9
1520345 67 39
1520345 673 9
1520345 6739
152034567 3 9
152034567 39
1520345673 9
15203456739


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.

New Comment







© 2021, kalkicode.com, All rights reserved