ADVERTISEMENT
ADVERTISEMENT

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

Given a character, we have to check whether the given character is alphanumeric or not using Rust program.
Submitted by Nidhi, on September 28, 2021

Problem Solution:

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

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.

Rust Basic Programs »



ADVERTISEMENT



ADVERTISEMENT



Comments and Discussions


ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.