Count positive integers with 0 as a digit and maximum ' d ' digits | C ++ program to find the count of natural numbers upto a given number of digits that contain atleast one zero ; Utility function to calculate the count of natural numbers upto a given number of digits that contain atleast one zero ; Sum of two GP series ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int findCountUpto ( int d ) { int GP1_Sum = 9 * ( ( pow ( 10 , d ) - 1 ) / 9 ) ; int GP2_Sum = 9 * ( ( pow ( 9 , d ) - 1 ) / 8 ) ; return GP1_Sum - GP2_Sum ; } int main ( ) { int d = 1 ; cout << findCountUpto ( d ) << endl ; d = 2 ; cout << findCountUpto ( d ) << endl ; d = 4 ; cout << findCountUpto ( d ) << endl ; return 0 ; }