Count of binary strings of given length consisting of at least one 1 | C ++ Program to implement the above approach ; Function to return the count of strings ; Calculate pow ( 2 , n ) ; Return pow ( 2 , n ) - 1 ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; long count_strings ( long n ) { int x = 1 ; for ( int i = 1 ; i < n ; i ++ ) { x = ( 1 << x ) ; } return x - 1 ; } int main ( ) { long n = 3 ; cout << count_strings ( n ) ; return 0 ; }