Check if a string represents a hexadecimal number or not | C ++ implementation of the above approach ; Function to check if the string represents a hexadecimal number ; Size of string ; Iterate over string ; Check if the character is invalid ; Print true if all characters are valid ; Driver code ; Given string ; Function call
#include <bits/stdc++.h> NEW_LINE using namespace std ; void checkHex ( string s ) { int n = s . length ( ) ; for ( int i = 0 ; i < n ; i ++ ) { char ch = s [ i ] ; if ( ( ch < '0' ch > '9' ) && ( ch < ' A ' ch > ' F ' ) ) { cout << " No " << endl ; return ; } } cout << " Yes " << endl ; } int main ( ) { string s = " BF57C " ; checkHex ( s ) ; return 0 ; }