The source code to check whether the given character is alphanumeric or not is given below. The given program is compiled and executed successfully.
// Rust program to check the given character
// is alphanumeric or not
fn main() {
let mut ch:char = 'A';
let mut ch1:char = '#';
if ( (ch >= '0' && ch <= '9') ||
(ch >= 'a' && ch <= 'z') ||
(ch >= 'A' && ch <= 'Z')
)
{
println!("Character '{}' is alphanumeric",ch);
}
else
{
println!("Character '{}' is not alphanumeric",ch);
}
if ( (ch1 >= '0' && ch1 <= '9') ||
(ch1 >= 'a' && ch1 <= 'z') ||
(ch1 >= 'A' && ch1 <= 'Z')
)
{
println!("Character '{}' is alphanumeric",ch1);
}
else
{
println!("Character '{}' is not alphanumeric",ch1);
}
}
Output:
Character 'A' is alphanumeric
Character '#' is not alphanumeric
Explanation:
Here, we created two characters variables ch and ch1 that are initialized with 'A' and '#' respectively. Then we checked the given characters are alphanumeric or not and printed the appropriate message.
Program/Source Code:
The source code to check whether the given character is alphanumeric or not is given below. The given program is compiled and executed successfully.
Output:
Explanation:
Here, we created two characters variables ch and ch1 that are initialized with 'A' and '#' respectively. Then we checked the given characters are alphanumeric or not and printed the appropriate message.
need an explanation for this answer? contact us directly to get an explanation for this answer