- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

# Find n’th number in a number system with only 3 and 4 in C++

In this problem, we are given an element N. we need to find the N’th number in a number system with only 3 and 4.

The number system consists of elements 3, 4, 33, 34, 43, 44, 333, 334, 343, 344, …

**Let’s take an example to understand the problem,**

## Input

N = 6

## Output

44

## Explanation

The numbers of the number system are − 3, 4, 33, 34, 43, 44...

## Solution Approach

The number system is similar to the binary number system but the number 0 is replaced by 3 and number 1 is replaced by 4.

Let’s say this as sBinary.

So, number Nth number is (n-1)’s Sbinary conversion.

With this knowledge, we can easily solve the problem by finding the binary equivalent of (N-1) and then adding each digit of the binary number found by 3.

How to Convert Decimal to Binary?

**Program to illustrate the working of our solution,**

## Example

#include<iostream> using namespace std; void findNThTermNumberSystem(int N) { if(N == 1 || N == 2) { cout<<(N-1) + 3; return; } N -= 1; findNThTermNumberSystem(N/2); cout<<((N % 2) + 3); } int main(){ int N = 12; cout<<N<<"th term of the number system is "; findNThTermNumberSystem(N); return 0; }

## Output

12th term of the number system is 434

- Related Questions & Answers
- n-th number with digits in {0, 1, 2, 3, 4, 5} in C++
- Finding n-th number made of prime digits (2, 3, 5 and 7) only in C++
- C++ Programe to find n-th term in series 1 2 2 3 3 3 4
- Program to find N-th term of series 2, 4, 3, 4, 15… in C++
- Find the number with set bits only between L-th and R-th index using C++
- N-th Tribonacci Number in C++
- N-th polite number in C++
- N-th root of a number in C++
- N-th Fibonacci number in Python Program
- n’th Pentagonal Number in C++
- N’th Smart Number in C++
- Find (1^n + 2^n + 3^n + 4^n) mod 5 in C++
- Convert to number with digits as 3 and 8 only in C++
- Find n-th element in a series with only 2 digits (and 7) allowed in C++
- Find M-th number whose repeated sum of digits of a number is N in C++

Advertisements