# Find two Composite Numbers such that there difference is N

Given a number **N**, the task is to find two composite numbers **X** and **Y**, such that difference between them is equal to **N**. Note that there can be multiple answers for this task. Print any one of them.

**Examples:**

Input:N = 4Output:X = 36, Y = 32Input:N = 1Output:X = 9, Y = 8

**Approach**:

- We have to find
**X – Y = N**. - We know, minimum value of
**N**can be**0**or**1**. If it is**0**, then we can print any composite number twice. - If
**N = 0**, then we can print**9*N**and**8 * N**, because these composite numbers have minimum difference between each other, i.e.,**1**. - We can also print
**15 * N**and**16 * N**, but we have to print any two composite numbers, so any of these are possible.

Below is the implementation of the

## C++

`#include <bits/stdc++.h> ` `using` `namespace` `std; ` `// C++ code to Find two Composite Numbers ` `// such that there difference is N ` ` ` `// Function to find the two composite numbers ` `void` `find_composite_nos(` `int` `n) ` `{ ` ` ` `cout << 9 * n << ` `" "` `<< 8 * n; ` `} ` ` ` `// Driver code ` `int` `main() ` `{ ` ` ` `int` `n = 4; ` ` ` ` ` `find_composite_nos(n); ` ` ` ` ` `return` `0; ` `} ` |

*chevron_right*

*filter_none*

## Java

`// Java code to Find two Composite Numbers ` `// such that there difference is N ` `class` `GFG ` `{ ` ` ` ` ` `// Function to find the two composite numbers ` ` ` `static` `void` `find_composite_nos(` `int` `n) ` ` ` `{ ` ` ` `System.out.println(` `9` `* n + ` `" "` `+ ` `8` `* n); ` ` ` `} ` ` ` ` ` `// Driver code ` ` ` `public` `static` `void` `main (String[] args) ` ` ` `{ ` ` ` `int` `n = ` `4` `; ` ` ` ` ` `find_composite_nos(n); ` ` ` `} ` `} ` ` ` `// This code is contributed by AnkitRai01 ` |

*chevron_right*

*filter_none*

## Python3

`# Python3 code to Find two Composite Numbers ` `# such that their difference is N ` ` ` `# Function to find the two composite numbers ` `def` `find_composite_nos(n) : ` ` ` ` ` `print` `(` `9` `*` `n, ` `8` `*` `n); ` ` ` `# Driver code ` `if` `__name__ ` `=` `=` `"__main__"` `: ` ` ` ` ` `n ` `=` `4` `; ` ` ` ` ` `find_composite_nos(n); ` ` ` `# This code is contributed by AnkitRai01 ` |

*chevron_right*

*filter_none*

## C#

`// C# code to Find two Composite Numbers ` `// such that there difference is N ` `using` `System; ` ` ` `class` `GFG ` `{ ` ` ` ` ` `// Function to find the two composite numbers ` ` ` `static` `void` `find_composite_nos(` `int` `n) ` ` ` `{ ` ` ` `Console.WriteLine(9 * n + ` `" "` `+ 8 * n); ` ` ` `} ` ` ` ` ` `// Driver code ` ` ` `public` `static` `void` `Main() ` ` ` `{ ` ` ` `int` `n = 4; ` ` ` ` ` `find_composite_nos(n); ` ` ` `} ` `} ` ` ` `// This code is contributed by AnkitRai01 ` |

*chevron_right*

*filter_none*

**Output:**

36 32

Don’t stop now and take your learning to the next level. Learn all the important concepts of Data Structures and Algorithms with the help of the most trusted course: **DSA Self Paced**. Become industry ready at a student-friendly price.

## Recommended Posts:

- Queries for the difference between the count of composite and prime numbers in a given range
- Find a range of composite numbers of given length
- Find a sequence of N prime numbers whose sum is a composite number
- Composite numbers with digit sum 1
- Highly Composite Numbers
- Product of all the Composite Numbers in an array
- Split n into maximum composite numbers
- Represent the given number as the sum of two composite numbers
- Sum of all composite numbers lying in the range [L, R] for Q queries
- Sum and Product of all Composite numbers which are divisible by k in an array
- Sum and product of k smallest and k largest composite numbers in the array
- Generate a list of n consecutive composite numbers (An interesting method)
- Find two numbers with the given LCM and minimum possible difference
- Program to find the percentage of difference between two numbers
- Find two numbers such that difference of their squares equal to N
- Find the largest composite number that divides N but is strictly lesser than N
- Find the minimum difference between Shifted tables of two numbers
- Find two numbers made up of a given digit such that their difference is divisible by N
- Find two numbers whose difference of fourth power is equal to N
- Program to find the maximum difference between the index of any two different numbers

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.