ADVERTISEMENT
ADVERTISEMENT

Rust program to demonstrate the relational operators

Here, we are going to demonstrate the relational operators in Rust programming language.
Submitted by Nidhi, on September 22, 2021

Problem Solution:

Here, we will create two integer variables and then compare the value of variables using relational operators and print appropriate messages.

Program/Source Code:

The source code to demonstrate the relational operators is given below. The given program is compiled and executed successfully.

// Rust program to demonstrate 
// the relational operators

fn main() {
    let mut num1:i32=22;
    let mut num2:i32=15;
    
    if(num1 == num2)
    {
        println!("Num1 is equal to Num2");
    }

    if(num1 != num2)
    {
        println!("Num1 is not equal to Num2");
    }

    if(num1 < num2)
    {
        println!("Num1 is less than Num2");
    }

    if(num1 > num2)
    {  
        println!("Num1 is greater than Num2");
    }

    if(num1 <= num2)
    {
        println!("Num1 is less than or equal to Num2");
    }

    if(num1 >= num2)
    {
        println!("Num1 is greater than or equal to Num2");
    }
}

Output:

Num1 is not equal to Num2
Num1 is greater than Num2
Num1 is greater than or equal to Num2

Explanation:

Here, we created two integer variables num1, num2, that are initialized with 22, 15 respectively. Then we compared variables using relational operators and printed the result.

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.