ADVERTISEMENT
ADVERTISEMENT

Rust program to check whether a given character is a punctuation mark or not

Given a character, we have to check whether it is a punctuation mark or not using Rust program.
Submitted by Nidhi, on September 28, 2021

Problem Solution:

Here, we will create a character variable and check given character is a punctuation mark or not.

Program/Source Code:

The source code to check a given character is a punctuation mark or not is given below. The given program is compiled and executed successfully.

// Rust program to check a given character 
// is a punctuation mark or not

fn main() {
    let ch:char = '#';
    
    if ( ch == '!' || ch == '\"' || ch == '#' || ch == '$' || ch == '%' || ch == '&' || ch == '\'' || ch == '(' || ch == ')' || ch == '*' || ch == '+' || ch == ',' || ch == '-' || ch == '.' || ch == '/' || ch == ':' || ch == ';' || ch == '<' || ch == '=' || ch == '>' || ch == '?' || ch == '@' || ch == '[' || ch == '\\' || ch == ']' || ch == '^' || ch == '`' || ch == '{' || ch == '|' || ch == '}')
    {
       println!("character '{}' is a punctuation mark",ch);
    }
    else
    {
       println!("character '{}' is a punctuation mark", ch);
    }  
}

Output:

character '#' is a punctuation mark

Explanation:

Here, we created a character variable ch with the initial value of '#'. Then we checked the given character contains a punctuation mark 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.