Count numbers from a given range having same first and last digits in their binary representation | C ++ program for the above approach ; Function to count numbers in range [ L , R ] having same first and last digit in the binary representation ; Drivers code ; Given range [ L , R ] ; Function Call
#include <bits/stdc++.h> NEW_LINE using namespace std ; void Count_numbers ( int L , int R ) { int count = ( R - L ) / 2 ; if ( R % 2 != 0 L % 2 != 0 ) count += 1 ; cout << count << endl ; } int main ( ) { int L = 6 , R = 30 ; Count_numbers ( L , R ) ; }