
- 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
Find the count of numbers that can be formed using digits 3 and 4 only and having length at max N in C++
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.
Example
#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); }
Output
Number of values: 14
- Related Articles
- 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 the difference between the greatest and the least 5 digit numbers formed by using the digits 6, 2 ,7, 4 ,3 each only once.
- 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++
- How many 3 digit numbers can you make using digits 2,4 and 0? (using each digit only once)(1) 6(2) 4(3) 3(4) 5
- Count of N-digit Numbers having Sum of even and odd positioned digits divisible by given numbers - JavaScript
- Count number of binary strings of length N having only 0’s and 1’s in C++
- Find the difference between the greatest and the least 5-digit numbers formed using digits 6,2,7,4,3 each only once.
- Find the largest number that can be formed with the given digits in C++
- Count of strings that can be formed from another string using each character at-most once in C++
- Count of numbers having only 1 set bit in the range [0, n] in C++
- Find the difference between the greatest and the least 5 -digit number that can be written using the digits \( 6,2,7,4,3 \) each only once.
- How many numbers can be formed by arranging the digits of the number 211 ?
- List all the three-digit numbers can be formed using the following numbers.(a) 4, 0 and 7. (b) 5, 6 and 9.
- Find if a molecule can be formed from 3 atoms using their valence numbers in C++

Advertisements