Count of m digit integers that are divisible by an integer n | C ++ program to count m digit numbers having n as divisor . ; Returns count of m digit numbers having n as divisor ; generating largest number of m digit ; generating largest number of m - 1 digit ; returning number of dividend ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int findCount ( int m , int n ) { int num1 = 0 ; for ( int i = 0 ; i < m ; i ++ ) num1 = ( num1 * 10 ) + 9 ; int num2 = 0 ; for ( int i = 0 ; i < ( m - 1 ) ; i ++ ) num2 = ( num2 * 10 ) + 9 ; return ( ( num1 / n ) - ( num2 / n ) ) ; } int main ( ) { int m = 2 , n = 6 ; printf ( " % d STRNEWLINE " , findCount ( m , n ) ) ; return 0 ; }