Check if all the digits of the given number are same | Function to check if all the digits in the number N is the same or not ; Get the length of N ; Form the number M of the type K * 111. . . where K is the rightmost digit of N ; Check if the numbers are equal ; Otherwise ; Driver Code
#include <iostream> NEW_LINE using namespace std ; string checkSameDigits ( int N ) { int length = ( N ) + 1 ; int M = ( ( 10 , length ) - 1 ) / ( 10 - 1 ) ; M *= N % 10 ; if ( M = N ) return " Yes " ; return " No " ; } int main ( ) { int N = 222 ; cout << checkSameDigits ( N ) ; }