Q:

Rust program to demonstrate the nested if-else statements

belongs to collection: Rust if/else Programs

0

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

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 demonstrate the nested if-else statements is given below. The given program is compiled and executed successfully.

// Rust program to demonstrate the 
// nested 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)
    {
        if(num1>num3)
        {
            large=num1;
        }
        else
        {
            large=num3;
        }
    }
    else if(num2>num3)
    {
        large=num2;
    }
    else
    {
        large=num3;
    }
 
    println!("Largest number is: {}",large);
}

Output:

Largest number is: 105

Explanation:

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

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

total answers (1)

Rust program to demonstrate the if let statement... >>
<< Rust program to demonstrate the ladder (multiple) ...