ADVERTISEMENT
ADVERTISEMENT

Rust program to demonstrate the ladder (multiple) if-else statements

Rust | Multiple if-else statements example: Given three numbers, we have to check the largest among three numbers.
Submitted by Nidhi, on October 03, 2021

Problem Solution:

Here, we are creating three integer variables and then find the largest number among them using the multiple (ladder) if-else statements.

Program/Source Code:

The source code to demonstrate the multiple (ladder) if-else statements is given below. The given program is compiled and executed successfully.

// Rust program to demonstrate the 
// multiple (ladder) if-else statements

fn main() {
    let mut num1:i32 = 95;
    let mut num2:i32 = 105;
    let mut num3:i32 = 75;
    
    let mut large:i32=0;

    if(num1>num2 && num1>num3)
    {
        large=num1;
    }
    else if(num2>num1 && num2>num3)
    {
        large=num2;
    }
    else
    {
        large=num3;
    }
    
    println!("Largest number is: {}",large);
}

Output:

Largest number is: 105

Explanation:

Here, we created 4 integer variables num1, num2, num3, and large. Those are initialized with 95, 105, 75, and 0 respectively. Then we checked and found the largest number using multiple if-else statements and printed the result.

Rust if/else 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.