GeeksforGeeks App
Open App
Browser
Continue

# Demlo number (Square of 11…1)

Given a number of the form 11..1 such that number of digits in it is smaller than 10, find square of the number.
Examples:

```Input : 111111
Output : 12345654321

Input : 1111
Output : 1234321```

Squares of 11…1 (where length is smaller than 10) are called Demlo numbers. A demlo number is number which consist of 1, 2, 3….n, n-1, n-2, …..1.
Demlo numbers are:

```1 = 1
11 * 11 = 121
111 * 111 = 12321
1111 * 1111 = 1234321```

To find demlo number, first we find append n numbers which are increasing and then append numbers which are decreasing.

## C++

 `// CPP program to print DemloNumber``#include ``using` `namespace` `std;` `// To return demlo number. This function assumes``// that the length of str is smaller than 10.``string printDemlo(string str)``{``    ``int` `len = str.length();``    ``string res = ``""``;` `    ``// Add numbers to res upto size``    ``// of str and then add number``    ``// reverse to it``    ``for` `(``int` `i = 1; i <= len; i++)``        ``res += ``char``(i + ``'0'``);` `    ``for` `(``int` `i = len - 1; i >= 1; i--)``        ``res += ``char``(i + ``'0'``);` `    ``return` `res;``}` `// Driver program to test printDemlo()``int` `main()``{``    ``string str = ``"111111"``;``    ``cout << printDemlo(str);``    ``return` `0;``}`

## Java

 `// Java program to print DemloNumber``public` `class` `Main {` `    ``// To return demlo number. This function assumes``    ``// that the length of str is smaller than 10.``    ``static` `String printDemlo(String str)``    ``{``        ``int` `len = str.length();``        ``String res = ``""``;` `        ``// Add numbers to res upto size``        ``// of str and then add number``        ``// reverse to it``        ``for` `(``int` `i = ``1``; i <= len; i++)``            ``res += Integer.toString(i);` `        ``for` `(``int` `i = len - ``1``; i >= ``1``; i--)``            ``res += Integer.toString(i);` `        ``return` `res;``    ``}` `    ``// Driver program to test printDemlo()``    ``public` `static` `void` `main(String[] args)``    ``{``        ``String str = ``"111111"``;``        ``System.out.println(printDemlo(str));``    ``}``}`

## Python3

 `# Python program to print Demlo Number` `# To return demlo number``# Length of s is smaller than 10``def` `printDemlo(s):``    ``l ``=` `len``(s)``    ``res ``=` `""``    ` `    ``# Add numbers to res upto size``    ``# of s then add in reverse``    ` `    ``for` `i ``in` `range``(``1``,l``+``1``):``        ``res ``=` `res ``+` `str``(i)``    ` `    ``for` `i ``in` `range``(l``-``1``,``0``,``-``1``):``        ``res ``=` `res ``+` `str``(i)``    ` `    ``return` `res``    `  `# Driver Code``s ``=` `"111111"`   `print` `(printDemlo(s))` `# Contributed by Harshit Agrawal`

## C#

 `// C# program to print DemloNumber``using` `System;``public` `class` `GFG {` `    ``// To return demlo number. This function assumes``    ``// that the length of str is smaller than 10.``    ``static` `String printDemlo(String str)``    ``{``        ``int` `len = str.Length;``        ``String res = ``""``;` `        ``// Add numbers to res upto size``        ``// of str and then add number``        ``// reverse to it``        ``for` `(``int` `i = 1; i <= len; i++)``            ``res += i.ToString();` `        ``for` `(``int` `i = len - 1; i >= 1; i--)``            ``res += i.ToString();` `        ``return` `res;``    ``}` `    ``// Driver program to test printDemlo()``    ``public` `static` `void` `Main()``    ``{``        ``String str = ``"111111"``;``        ``Console.WriteLine(printDemlo(str));``    ``}``}``// This code is contributed by mits`

## PHP

 `= 1; ``\$i``--)``        ``\$res` `.= ``chr``(``\$i` `+ 48);` `    ``return` `\$res``;``}` `// Driver Code``\$str` `= ``"111111"``;``echo` `printDemlo(``\$str``);` `// This code is contributed by mits``?>`

## Javascript

 ``

Output:

`12345654321`

Time complexity: O(log N) where N is the length of string “str” of number n

Auxiliary space: O(1) because it is using constant space

This article is contributed by nuclode. If you like GeeksforGeeks and would like to contribute, you can also write an article using write.geeksforgeeks.org or mail your article to review-team@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.