In this tutorial, we will be discussing a program to find the numbers having ‘d’ digits with 0 as a digit.
For this we will be provided with a number ‘d’. Our task is to count and print the number of positive integers having ‘d’ digits and 0 as one of their digit.
Example
#include<bits/stdc++.h>
using namespace std;
//counting the number of 'd' digit numbers
int count_num(int d) {
return 9*(pow(10,d-1) - pow(9,d-1));
}
int main(){
int d = 1;
cout << count_num(d) << endl;
d = 2;
cout << count_num(d) << endl;
d = 4;
cout << count_num(d) << endl;
return 0;
}Output
0 9 2439