# Split a number into three parts

Here given code implementation process.

``````/*
C Program
Break the number into three parts
*/
#include <stdio.h>

//Break a number in three parts that sum equal to given value
void break_number(int number)
{
//Variables which is controlling the execution process of loop
int start = 0, ends = number;
if (number < 0)
{
//Special case
//When number is less than zero
start = number;
ends = 0;
}
printf("\nNumber : %d\n\n", number);
//This loop indicates first number
for (int i = start; i <= ends; ++i)
{
//This loop indicates second number
for (int j = start; j <= ends; ++j)
{
//This loop indicates third number
for (int k = start; k <= ends; ++k)
{
//Check whether sum of three numbers is equal to given number
if (number == (i + j + k))
{
//Display the resultant numbers
printf("%d  %d  %d\n", i, j, k);
}
}
}
}
}
int main()
{
//Simple Case
break_number(7);
break_number(5);
break_number(-5);
break_number(2);
return 0;
}``````

#### Output

``````Number : 7

0  0  7
0  1  6
0  2  5
0  3  4
0  4  3
0  5  2
0  6  1
0  7  0
1  0  6
1  1  5
1  2  4
1  3  3
1  4  2
1  5  1
1  6  0
2  0  5
2  1  4
2  2  3
2  3  2
2  4  1
2  5  0
3  0  4
3  1  3
3  2  2
3  3  1
3  4  0
4  0  3
4  1  2
4  2  1
4  3  0
5  0  2
5  1  1
5  2  0
6  0  1
6  1  0
7  0  0

Number : 5

0  0  5
0  1  4
0  2  3
0  3  2
0  4  1
0  5  0
1  0  4
1  1  3
1  2  2
1  3  1
1  4  0
2  0  3
2  1  2
2  2  1
2  3  0
3  0  2
3  1  1
3  2  0
4  0  1
4  1  0
5  0  0

Number : -5

-5  0  0
-4  -1  0
-4  0  -1
-3  -2  0
-3  -1  -1
-3  0  -2
-2  -3  0
-2  -2  -1
-2  -1  -2
-2  0  -3
-1  -4  0
-1  -3  -1
-1  -2  -2
-1  -1  -3
-1  0  -4
0  -5  0
0  -4  -1
0  -3  -2
0  -2  -3
0  -1  -4
0  0  -5

Number : 2

0  0  2
0  1  1
0  2  0
1  0  1
1  1  0
2  0  0``````
``````// Java Program
// Break the number into three parts
class MyMath
{
//Break a number in three parts that sum equal to given value
public void break_number(int number)
{
//Variables which is controlling the execution process of loop
int start = 0, ends = number;
if (number < 0)
{
//Special case
//When number is less than zero
start = number;
ends = 0;
}
System.out.print("\nNumber : " + number + "\n");
//This loop indicates first number
for (int i = start; i <= ends; ++i)
{
//This loop indicates second number
for (int j = start; j <= ends; ++j)
{
//This loop indicates third number
for (int k = start; k <= ends; ++k)
{
//Check whether sum of three numbers is equal to given number
if (number == (i + j + k))
{
//Display the resultant numbers
System.out.print(i + " " + j + " " + k + "\n");
}
}
}
}
}
public static void main(String[] args)
{
MyMath obj = new MyMath();
//Simple Case
obj.break_number(7);
obj.break_number(5);
obj.break_number(-5);
obj.break_number(2);
}
}``````

#### Output

``````Number : 7
0 0 7
0 1 6
0 2 5
0 3 4
0 4 3
0 5 2
0 6 1
0 7 0
1 0 6
1 1 5
1 2 4
1 3 3
1 4 2
1 5 1
1 6 0
2 0 5
2 1 4
2 2 3
2 3 2
2 4 1
2 5 0
3 0 4
3 1 3
3 2 2
3 3 1
3 4 0
4 0 3
4 1 2
4 2 1
4 3 0
5 0 2
5 1 1
5 2 0
6 0 1
6 1 0
7 0 0

Number : 5
0 0 5
0 1 4
0 2 3
0 3 2
0 4 1
0 5 0
1 0 4
1 1 3
1 2 2
1 3 1
1 4 0
2 0 3
2 1 2
2 2 1
2 3 0
3 0 2
3 1 1
3 2 0
4 0 1
4 1 0
5 0 0

Number : -5
-5 0 0
-4 -1 0
-4 0 -1
-3 -2 0
-3 -1 -1
-3 0 -2
-2 -3 0
-2 -2 -1
-2 -1 -2
-2 0 -3
-1 -4 0
-1 -3 -1
-1 -2 -2
-1 -1 -3
-1 0 -4
0 -5 0
0 -4 -1
0 -3 -2
0 -2 -3
0 -1 -4
0 0 -5

Number : 2
0 0 2
0 1 1
0 2 0
1 0 1
1 1 0
2 0 0``````
``````// C++ Program
// Break the number into three parts
#include<iostream>

using namespace std;
class MyMath
{
public:
//Break a number in three parts that sum equal to given value
void break_number(int number)
{
//Variables which is controlling the execution process of loop
int start = 0, ends = number;
if (number < 0)
{
//Special case
//When number is less than zero
start = number;
ends = 0;
}
cout << "\nNumber : " << number << "\n";
//This loop indicates first number
for (int i = start; i <= ends; ++i)
{
//This loop indicates second number
for (int j = start; j <= ends; ++j)
{
//This loop indicates third number
for (int k = start; k <= ends; ++k)
{
//Check whether sum of three numbers is equal to given number
if (number == (i + j + k))
{
cout << i << " " << j << " " << k << "\n";
}
}
}
}
}
};
int main()
{
MyMath obj ;
//Simple Case
obj.break_number(7);
obj.break_number(5);
obj.break_number(-5);
obj.break_number(2);
return 0;
}``````

#### Output

``````Number : 7
0 0 7
0 1 6
0 2 5
0 3 4
0 4 3
0 5 2
0 6 1
0 7 0
1 0 6
1 1 5
1 2 4
1 3 3
1 4 2
1 5 1
1 6 0
2 0 5
2 1 4
2 2 3
2 3 2
2 4 1
2 5 0
3 0 4
3 1 3
3 2 2
3 3 1
3 4 0
4 0 3
4 1 2
4 2 1
4 3 0
5 0 2
5 1 1
5 2 0
6 0 1
6 1 0
7 0 0

Number : 5
0 0 5
0 1 4
0 2 3
0 3 2
0 4 1
0 5 0
1 0 4
1 1 3
1 2 2
1 3 1
1 4 0
2 0 3
2 1 2
2 2 1
2 3 0
3 0 2
3 1 1
3 2 0
4 0 1
4 1 0
5 0 0

Number : -5
-5 0 0
-4 -1 0
-4 0 -1
-3 -2 0
-3 -1 -1
-3 0 -2
-2 -3 0
-2 -2 -1
-2 -1 -2
-2 0 -3
-1 -4 0
-1 -3 -1
-1 -2 -2
-1 -1 -3
-1 0 -4
0 -5 0
0 -4 -1
0 -3 -2
0 -2 -3
0 -1 -4
0 0 -5

Number : 2
0 0 2
0 1 1
0 2 0
1 0 1
1 1 0
2 0 0``````
``````// C# Program
// Break the number into three parts
using System;
class MyMath
{
//Break a number in three parts that sum equal to given value
public void break_number(int number)
{
//Variables which is controlling the execution process of loop
int start = 0, ends = number;
if (number < 0)
{
//Special case
//When number is less than zero
start = number;
ends = 0;
}
Console.Write("\nNumber : " + number + "\n");
//This loop indicates first number
for (int i = start; i <= ends; ++i)
{
//This loop indicates second number
for (int j = start; j <= ends; ++j)
{
//This loop indicates third number
for (int k = start; k <= ends; ++k)
{
//Check whether sum of three numbers is equal to given number
if (number == (i + j + k))
{
Console.Write(i + " " + j + " " + k + "\n");
}
}
}
}
}
public static void Main(String[] args)
{
MyMath obj = new MyMath();
//Simple Case
obj.break_number(7);
obj.break_number(5);
obj.break_number(-5);
obj.break_number(2);
}
}``````

#### Output

``````Number : 7
0 0 7
0 1 6
0 2 5
0 3 4
0 4 3
0 5 2
0 6 1
0 7 0
1 0 6
1 1 5
1 2 4
1 3 3
1 4 2
1 5 1
1 6 0
2 0 5
2 1 4
2 2 3
2 3 2
2 4 1
2 5 0
3 0 4
3 1 3
3 2 2
3 3 1
3 4 0
4 0 3
4 1 2
4 2 1
4 3 0
5 0 2
5 1 1
5 2 0
6 0 1
6 1 0
7 0 0

Number : 5
0 0 5
0 1 4
0 2 3
0 3 2
0 4 1
0 5 0
1 0 4
1 1 3
1 2 2
1 3 1
1 4 0
2 0 3
2 1 2
2 2 1
2 3 0
3 0 2
3 1 1
3 2 0
4 0 1
4 1 0
5 0 0

Number : -5
-5 0 0
-4 -1 0
-4 0 -1
-3 -2 0
-3 -1 -1
-3 0 -2
-2 -3 0
-2 -2 -1
-2 -1 -2
-2 0 -3
-1 -4 0
-1 -3 -1
-1 -2 -2
-1 -1 -3
-1 0 -4
0 -5 0
0 -4 -1
0 -3 -2
0 -2 -3
0 -1 -4
0 0 -5

Number : 2
0 0 2
0 1 1
0 2 0
1 0 1
1 1 0
2 0 0``````
``````<?php
// Php Program
// Break the number into three parts
class MyMath
{
//Break a number in three parts that sum equal to given value
public  function break_number(\$number)
{
//Variables which is controlling the execution process of loop
\$start = 0;
\$ends = \$number;
if (\$number < 0)
{
//Special case
//When number is less than zero
\$start = \$number;
\$ends = 0;
}
echo "\nNumber : ". \$number ."\n";
//This loop indicates first number
for (\$i = \$start; \$i <= \$ends; ++\$i)
{
//This loop indicates second number
for (\$j = \$start; \$j <= \$ends; ++\$j)
{
//This loop indicates third number
for (\$k = \$start; \$k <= \$ends; ++\$k)
{
//Check whether sum of three numbers is equal to given number
if (\$number == (\$i + \$j + \$k))
{
echo \$i ." ". \$j ." ". \$k ."\n";
}
}
}
}
}
}

function main()
{
\$obj = new MyMath();
//Simple Case
\$obj->break_number(7);
\$obj->break_number(5);
\$obj->break_number(-5);
\$obj->break_number(2);
}
main();``````

#### Output

``````Number : 7
0 0 7
0 1 6
0 2 5
0 3 4
0 4 3
0 5 2
0 6 1
0 7 0
1 0 6
1 1 5
1 2 4
1 3 3
1 4 2
1 5 1
1 6 0
2 0 5
2 1 4
2 2 3
2 3 2
2 4 1
2 5 0
3 0 4
3 1 3
3 2 2
3 3 1
3 4 0
4 0 3
4 1 2
4 2 1
4 3 0
5 0 2
5 1 1
5 2 0
6 0 1
6 1 0
7 0 0

Number : 5
0 0 5
0 1 4
0 2 3
0 3 2
0 4 1
0 5 0
1 0 4
1 1 3
1 2 2
1 3 1
1 4 0
2 0 3
2 1 2
2 2 1
2 3 0
3 0 2
3 1 1
3 2 0
4 0 1
4 1 0
5 0 0

Number : -5
-5 0 0
-4 -1 0
-4 0 -1
-3 -2 0
-3 -1 -1
-3 0 -2
-2 -3 0
-2 -2 -1
-2 -1 -2
-2 0 -3
-1 -4 0
-1 -3 -1
-1 -2 -2
-1 -1 -3
-1 0 -4
0 -5 0
0 -4 -1
0 -3 -2
0 -2 -3
0 -1 -4
0 0 -5

Number : 2
0 0 2
0 1 1
0 2 0
1 0 1
1 1 0
2 0 0``````
``````// Node Js Program
// Break the number into three parts
class MyMath
{
//Break a number in three parts that sum equal to given value
break_number(number)
{
//Variables which is controlling the execution process of loop
var start = 0;
var ends = number;
if (number < 0)
{
//Special case
//When number is less than zero
start = number;
ends = 0;
}
process.stdout.write("\nNumber : " + number + "\n");
//This loop indicates first number
for (var i = start; i <= ends; ++i)
{
//This loop indicates second number
for (var j = start; j <= ends; ++j)
{
//This loop indicates third number
for (var k = start; k <= ends; ++k)
{
//Check whether sum of three numbers is equal to given number
if (number == (i + j + k))
{
process.stdout.write(i + " " + j + " " + k + "\n");
}
}
}
}
}
}

function main()
{
var obj = new MyMath();
//Simple Case
obj.break_number(7);
obj.break_number(5);
obj.break_number(-5);
obj.break_number(2);
}
main();``````

#### Output

``````Number : 7
0 0 7
0 1 6
0 2 5
0 3 4
0 4 3
0 5 2
0 6 1
0 7 0
1 0 6
1 1 5
1 2 4
1 3 3
1 4 2
1 5 1
1 6 0
2 0 5
2 1 4
2 2 3
2 3 2
2 4 1
2 5 0
3 0 4
3 1 3
3 2 2
3 3 1
3 4 0
4 0 3
4 1 2
4 2 1
4 3 0
5 0 2
5 1 1
5 2 0
6 0 1
6 1 0
7 0 0

Number : 5
0 0 5
0 1 4
0 2 3
0 3 2
0 4 1
0 5 0
1 0 4
1 1 3
1 2 2
1 3 1
1 4 0
2 0 3
2 1 2
2 2 1
2 3 0
3 0 2
3 1 1
3 2 0
4 0 1
4 1 0
5 0 0

Number : -5
-5 0 0
-4 -1 0
-4 0 -1
-3 -2 0
-3 -1 -1
-3 0 -2
-2 -3 0
-2 -2 -1
-2 -1 -2
-2 0 -3
-1 -4 0
-1 -3 -1
-1 -2 -2
-1 -1 -3
-1 0 -4
0 -5 0
0 -4 -1
0 -3 -2
0 -2 -3
0 -1 -4
0 0 -5

Number : 2
0 0 2
0 1 1
0 2 0
1 0 1
1 1 0
2 0 0``````
``````#  Python 3 Program
#  Break the number into three parts
class MyMath :
# Break a number in three parts that sum equal to given value
def break_number(self, number) :
# Variables which is controlling the execution process of loop
start = 0
ends = number
if (number < 0) :
# Special case
# When number is less than zero
start = number
ends = 0

print("\nNumber : ", number ,"\n", end = "")

i = start
j = start
k = start
# This loop indicates first number
while (i <= ends) :
j = start
# This loop indicates second number
while (j <= ends) :
k = start
# This loop indicates third number
while (k <= ends) :
# Check whether sum of three numbers is equal to given number
if (number == (i + j + k)) :
print(i ," ", j ," ", k ,"\n", end = "")

k += 1

j += 1

i += 1

def main() :
obj = MyMath()
# Simple Case
obj.break_number(7)
obj.break_number(5)
obj.break_number(-5)
obj.break_number(2)

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

#### Output

``````Number :  7
0   0   7
0   1   6
0   2   5
0   3   4
0   4   3
0   5   2
0   6   1
0   7   0
1   0   6
1   1   5
1   2   4
1   3   3
1   4   2
1   5   1
1   6   0
2   0   5
2   1   4
2   2   3
2   3   2
2   4   1
2   5   0
3   0   4
3   1   3
3   2   2
3   3   1
3   4   0
4   0   3
4   1   2
4   2   1
4   3   0
5   0   2
5   1   1
5   2   0
6   0   1
6   1   0
7   0   0

Number :  5
0   0   5
0   1   4
0   2   3
0   3   2
0   4   1
0   5   0
1   0   4
1   1   3
1   2   2
1   3   1
1   4   0
2   0   3
2   1   2
2   2   1
2   3   0
3   0   2
3   1   1
3   2   0
4   0   1
4   1   0
5   0   0

Number :  -5
-5   0   0
-4   -1   0
-4   0   -1
-3   -2   0
-3   -1   -1
-3   0   -2
-2   -3   0
-2   -2   -1
-2   -1   -2
-2   0   -3
-1   -4   0
-1   -3   -1
-1   -2   -2
-1   -1   -3
-1   0   -4
0   -5   0
0   -4   -1
0   -3   -2
0   -2   -3
0   -1   -4
0   0   -5

Number :  2
0   0   2
0   1   1
0   2   0
1   0   1
1   1   0
2   0   0``````
``````#  Ruby Program
#  Break the number into three parts
class MyMath

# Break a number in three parts that sum equal to given value
def break_number(number)

# Variables which is controlling the execution process of loop
start = 0
ends = number
if (number < 0)

# Special case
# When number is less than zero
start = number
ends = 0
end
print("\nNumber : ", number ,"\n")

i = start
j = start
k = start
# This loop indicates first number
while (i <= ends)

j = start
# This loop indicates second number
while (j <= ends)

k = start
# This loop indicates third number
while (k <= ends)

# Check whether sum of three numbers is equal to given number
if (number == (i + j + k))

# Display the resultant numbers
print(i ," ", j ," ", k ,"\n")
end
k += 1
end
j += 1
end
i += 1
end
end
end
def main()

obj = MyMath.new()
# Simple Case
obj.break_number(7)
obj.break_number(5)
obj.break_number(-5)
obj.break_number(2)
end
main()``````

#### Output

``````Number : 7
0 0 7
0 1 6
0 2 5
0 3 4
0 4 3
0 5 2
0 6 1
0 7 0
1 0 6
1 1 5
1 2 4
1 3 3
1 4 2
1 5 1
1 6 0
2 0 5
2 1 4
2 2 3
2 3 2
2 4 1
2 5 0
3 0 4
3 1 3
3 2 2
3 3 1
3 4 0
4 0 3
4 1 2
4 2 1
4 3 0
5 0 2
5 1 1
5 2 0
6 0 1
6 1 0
7 0 0

Number : 5
0 0 5
0 1 4
0 2 3
0 3 2
0 4 1
0 5 0
1 0 4
1 1 3
1 2 2
1 3 1
1 4 0
2 0 3
2 1 2
2 2 1
2 3 0
3 0 2
3 1 1
3 2 0
4 0 1
4 1 0
5 0 0

Number : -5
-5 0 0
-4 -1 0
-4 0 -1
-3 -2 0
-3 -1 -1
-3 0 -2
-2 -3 0
-2 -2 -1
-2 -1 -2
-2 0 -3
-1 -4 0
-1 -3 -1
-1 -2 -2
-1 -1 -3
-1 0 -4
0 -5 0
0 -4 -1
0 -3 -2
0 -2 -3
0 -1 -4
0 0 -5

Number : 2
0 0 2
0 1 1
0 2 0
1 0 1
1 1 0
2 0 0
``````
``````// Scala Program
// Break the number into three parts
class MyMath
{
//Break a number in three parts that sum equal to given value
def break_number(number: Int): Unit = {
//Variables which is controlling the execution process of loop
var start: Int = 0;
var ends: Int = number;
if (number < 0)
{
//Special case
//When number is less than zero
start = number;
ends = 0;
}
print("\nNumber : " + number + "\n");

var i: Int = start;
var j: Int = start;
var k: Int = start;
//This loop indicates first number
while (i <= ends)
{
j = start;
//This loop indicates second number
while (j <= ends)
{
k = start;
//This loop indicates third number
while (k <= ends)
{
//Check whether sum of three numbers is equal to given number
if (number == (i + j + k))
{
//Display the resultant numbers
print(" "+i + " " + j + " " + k + "\n");
}
k += 1;
}
j += 1;
}
i += 1;
}
}
}
object Main
{
def main(args: Array[String]): Unit = {
var obj: MyMath = new MyMath();
//Simple Case
obj.break_number(7);
obj.break_number(5);
obj.break_number(-5);
obj.break_number(2);
}
}``````

#### Output

``````Number : 7
0 0 7
0 1 6
0 2 5
0 3 4
0 4 3
0 5 2
0 6 1
0 7 0
1 0 6
1 1 5
1 2 4
1 3 3
1 4 2
1 5 1
1 6 0
2 0 5
2 1 4
2 2 3
2 3 2
2 4 1
2 5 0
3 0 4
3 1 3
3 2 2
3 3 1
3 4 0
4 0 3
4 1 2
4 2 1
4 3 0
5 0 2
5 1 1
5 2 0
6 0 1
6 1 0
7 0 0

Number : 5
0 0 5
0 1 4
0 2 3
0 3 2
0 4 1
0 5 0
1 0 4
1 1 3
1 2 2
1 3 1
1 4 0
2 0 3
2 1 2
2 2 1
2 3 0
3 0 2
3 1 1
3 2 0
4 0 1
4 1 0
5 0 0

Number : -5
-5 0 0
-4 -1 0
-4 0 -1
-3 -2 0
-3 -1 -1
-3 0 -2
-2 -3 0
-2 -2 -1
-2 -1 -2
-2 0 -3
-1 -4 0
-1 -3 -1
-1 -2 -2
-1 -1 -3
-1 0 -4
0 -5 0
0 -4 -1
0 -3 -2
0 -2 -3
0 -1 -4
0 0 -5

Number : 2
0 0 2
0 1 1
0 2 0
1 0 1
1 1 0
2 0 0``````
``````// Swift Program
// Break the number into three parts
class MyMath
{
//Break a number in three parts that sum equal to given value
func break_number(_ number: Int)
{
//Variables which is controlling the execution process of loop
var start: Int = 0;
var ends: Int = number;
if (number < 0)
{
//Special case
//When number is less than zero
start = number;
ends = 0;
}
print("\nNumber : ", number ,"\n", terminator: "");

var i: Int = start;
var j: Int = start;
var k: Int = start;
//This loop indicates first number
while (i <= ends)
{
j = start;
//This loop indicates second number
while (j <= ends)
{
k = start;
//This loop indicates third number
while (k <= ends)
{
//Check whether sum of three numbers is equal to given number
if (number == (i + j + k))
{
print(i ," ", j ," ", k ,"\n", terminator: "");
}
k += 1;
}
j += 1;
}
i += 1;
}
}
}
func main()
{
let obj: MyMath = MyMath();
//Simple Case
obj.break_number(7);
obj.break_number(5);
obj.break_number(-5);
obj.break_number(2);
}
main();``````

#### Output

``````Number :  7
0   0   7
0   1   6
0   2   5
0   3   4
0   4   3
0   5   2
0   6   1
0   7   0
1   0   6
1   1   5
1   2   4
1   3   3
1   4   2
1   5   1
1   6   0
2   0   5
2   1   4
2   2   3
2   3   2
2   4   1
2   5   0
3   0   4
3   1   3
3   2   2
3   3   1
3   4   0
4   0   3
4   1   2
4   2   1
4   3   0
5   0   2
5   1   1
5   2   0
6   0   1
6   1   0
7   0   0

Number :  5
0   0   5
0   1   4
0   2   3
0   3   2
0   4   1
0   5   0
1   0   4
1   1   3
1   2   2
1   3   1
1   4   0
2   0   3
2   1   2
2   2   1
2   3   0
3   0   2
3   1   1
3   2   0
4   0   1
4   1   0
5   0   0

Number :  -5
-5   0   0
-4   -1   0
-4   0   -1
-3   -2   0
-3   -1   -1
-3   0   -2
-2   -3   0
-2   -2   -1
-2   -1   -2
-2   0   -3
-1   -4   0
-1   -3   -1
-1   -2   -2
-1   -1   -3
-1   0   -4
0   -5   0
0   -4   -1
0   -3   -2
0   -2   -3
0   -1   -4
0   0   -5

Number :  2
0   0   2
0   1   1
0   2   0
1   0   1
1   1   0
2   0   0``````

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