Check if all the digits of the given number are same | C ++ Program to implement the above approach ; Function to check if all the digits in the number N is the same or not ; Find the last digit ; Find the current last digit ; Update the value of N ; If there exists any distinct digit , then return No ; Otherwise , return Yes ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; string checkSameDigits ( int N ) { int digit = N % 10 ; while ( N != 0 ) { int current_digit = N % 10 ; N = N / 10 ; if ( current_digit != digit ) { return " No " ; } } return " Yes " ; } int main ( ) { int N = 222 ; cout << ( checkSameDigits ( N ) ) ; return 0 ; }