Count of all possible numbers not exceeding M having suffix N | C ++ Program to implement the above approach ; Function to count the no . of digits of N ; Function to count all possible numbers having Suffix as N ; Difference of the A . P ; Count of the number of terms ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int digitsOf ( int num ) { return to_string ( num ) . size ( ) ; } int count ( int a , int tn ) { int diff = pow ( 10 , digitsOf ( a ) ) ; return ( ( tn - a ) / diff ) + 1 ; } int main ( ) { int n , m ; n = 25 , m = 4500 ; cout << count ( n , m ) ; return 0 ; }