Find the total count of numbers up to N digits in a given base B | C ++ implementation to find the count of natural numbers upto N digits ; Function to return the count of natural numbers upto N digits ; Loop to iterate from 1 to N and calculating number of natural numbers for every ' i ' th digit . ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int count ( int N , int B ) { int sum = 0 ; for ( int i = 1 ; i <= N ; i ++ ) { sum += ( B - 1 ) * pow ( B , i - 1 ) ; } return sum ; } int main ( ) { int N = 2 , B = 10 ; cout << count ( N , B ) ; return 0 ; }