- 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

Given a number N. We have to find the count of such numbers that can be formed using digit 3 and 4. So if N = 6, then the numbers will be 3, 4, 33, 34, 43, 44.

We can solve this problem if we look closely, for single digit number it has 2 numbers 3 and 4, for digit 2, it has 4 numbers 33, 34, 43, 44. So for m digit numbers, it will have 2m values.

#include<iostream> #include<cmath> using namespace std; long long countNumbers(int n) { return (long long)(pow(2, n + 1)) - 2; } int main() { int n = 3; cout << "Number of values: " << countNumbers(n); }

Number of values: 14

- Related Questions & Answers
- Count of alphabets whose ASCII values can be formed with the digits of N in C++
- Find maximum number that can be formed using digits of a given number in C++
- Find the largest number that can be formed with the given digits in C++
- Count of numbers between range having only non-zero digits whose sum of digits is N and number is divisible by M in C++
- Find if a molecule can be formed from 3 atoms using their valence numbers in C++
- Count of strings that can be formed from another string using each character at-most once in C++
- Count number of binary strings of length N having only 0’s and 1’s in C++
- Count of N-digit Numbers having Sum of even and odd positioned digits divisible by given numbers - JavaScript
- Find n’th number in a number system with only 3 and 4 in C++
- Maximum possible time that can be formed from four digits in C++
- Count of numbers having only 1 set bit in the range [0, n] in C++
- Print all possible strings of length k that can be formed from a set of n characters in C++
- Count of different ways to express N as the sum of 1, 3 and 4 in C++
- Print all distinct integers that can be formed by K numbers from a given array of N numbers in C++
- Program to find length of longest word that can be formed from given letters in python

Advertisements