Q:

Rust program to check whether the given character is alphanumeric or not

belongs to collection: Rust Basic Programs

0

Here, we will create two-character variables and check created characters contains an alphanumeric value or not.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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.

// 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.

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Rust Basic Programs

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
Rust program to check whether a character variable... >>
<< Rust program to calculate the HCF (Highest Common ...