- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

We are given a number N as input. The goal is to find all N digit numbers that have an even number of 0’s as digits. The number also could have preceding zeros like in case of N=3 numbers included will be 001,002,003….010….so on.

Let us understand with examples.

**Input** − N=4

**Output** − Count of no. with N digits which consists of even number of 0's are − 7047

**Explanation** − All 4 digits numbers would be like −

Smallest will be 0000, then 0011,0012,0013,0014…..Highest will be 9900.

**Input** − N=5

**Output** − Count of no. with N digits which consists of even number of 0's are − 66383

**Explanation** − All 5 digit numbers would be like −

Smallest will be 00001, then 00002,00003,00004…..Highest will be 99900.

We will first calculate the total N digit numbers that are T=10N-1. Then calculate all N digit numbers with odd 0’s as digits, that is O=10N-8N . The remaining numbers with Even 0’s in digits will be T-O/2.

Take an integer N as input.

Function count_even(int N) takes N and returns the count of N digit numbers with even 0’s.

Total N digit numbers are total=pow(10,N)-1

Total N digit numbers with odd 0’s in digit are odd=pow(10,N)-pow(8,N).

Leftover even 0’s in digit are even=total-odd/2.

Return even as a count of N digit numbers with even numbers of 0’s.

#include <bits/stdc++.h> using namespace std; int count_even(int N){ int total = pow(10, N) - 1; int odd = pow(10, N) - pow(8, N); int even = total - odd / 2; return even; } int main(){ int N = 3; cout<<"Count of Numbers with N digits which consists of even number of 0's are: "<<count_even(N); return 0; }

If we run the above code it will generate the following output- −

Count of Numbers with N digits which consists of even number of 0's are: 755

- Related Questions & Answers
- Count Numbers with N digits which consists of odd number of 0's in C++
- Fetch Numbers with Even Number of Digits JavaScript
- Find Numbers with Even Number of Digits in Python
- Count digits in given number N which divide N in C++
- Program to count number of stepping numbers of n digits in python
- Find the number of integers from 1 to n which contains digits 0’s and 1’s only in C++
- Count rotations of N which are Odd and Even in C++
- Total number of non-decreasing numbers with n digits
- Count subarrays with equal number of 1’s and 0’s in C++
- Count number of binary strings of length N having only 0’s and 1’s in C++
- MySQL query to add 0's to numbers with less than 9 digits?
- Count of N-digit Numbers having Sum of even and odd positioned digits divisible by given numbers - JavaScript
- C# Program to Count the Number of 1's in the Entered Numbers
- Design a DFA machine accepting odd numbers of 0’s or even numbers of 1’s
- Count total number of digits from 1 to N in C++

Advertisements