
- C++ Basics
- C++ Home
- C++ Overview
- C++ Environment Setup
- C++ Basic Syntax
- C++ Comments
- C++ Data Types
- C++ Variable Types
- C++ Variable Scope
- C++ Constants/Literals
- C++ Modifier Types
- C++ Storage Classes
- C++ Operators
- C++ Loop Types
- C++ Decision Making
- C++ Functions
- C++ Numbers
- C++ Arrays
- C++ Strings
- C++ Pointers
- C++ References
- C++ Date & Time
- C++ Basic Input/Output
- C++ Data Structures
- C++ Object Oriented
- C++ Classes & Objects
- C++ Inheritance
- C++ Overloading
- C++ Polymorphism
- C++ Abstraction
- C++ Encapsulation
- C++ Interfaces
Demlo number, Square of 11...1 in C++ Program
In this tutorial, we are going to learn about the demlo number.
The demlo numbers are the squares of the number 1, 11, 111, 1111, etc.., We can easily find the demlo number as it is in the form 1 2 3 4 5 ... n-2 n-1 n n-1 n-2 ... 5 4 3 2 1.
Here, we are given a number which has only ones. And we need to find the demlo number of that number. Let's see an example.
Input − 1111111
Output − 1234567654321
Let's see the steps to solve the problem.
Initialize the number in a string format.
Initialize an empty string to store the demlo number.
Iterate from 1 to the length of the number n.
Add all the numbers to the demlo number.
Now, iterate from n - 1 to 1.
Add all the numbers to the demlo number.
Print the demlo number.
Example
Let's see the code.
#include <bits/stdc++.h> using namespace std; string getDemloNumber(string str) { int len = str.length(); string demloNumber = ""; for (int i = 1; i <= len; i++) { demloNumber += char(i + '0'); } for (int i = len - 1; i >= 1; i--) { demloNumber += char(i + '0'); } return demloNumber; } int main() { string str = "1111111"; cout << getDemloNumber(str) << endl; return 0; }
Output
If you run the above code, then you will get the following result.
1234567654321
Conclusion
If you have any queries in the tutorial, mention them in the comment section.
- Related Articles
- Demlo number (Square of 11...1)” in C++?
- Program to find number of square submatrices with 1 in python
- The Property Satisfies the condition for addition of whole number (78+1)+11=78+(1+11) is ___________
- Find the square of each number. 1) 14 2) 0.17
- 8086 program to find the square root of a perfect square root number
- 8086 program to find Square Root of a number
- 8085 program to find square root of a number
- 8085 program to find square of a 8 bit number
- Program to count number of square submatrices in given binary matrix in Python
- Program to find N-th term of series 1, 2, 11, 12, 21… in C++
- Java program to find the square root of a given number
- Haskell Program to calculate the square root of the given number
- Program to count number of square submatix of 1s in the given matrix in C++
- Program to find number of bit 1 in the given number in Python
- Program to find number of ways where square of number is equal to product of two numbers in Python
