- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Count ‘d’ digit positive integers with 0 as a digit in C++
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
Advertisements