ADVERTISEMENT
ADVERTISEMENT

Rust program to demonstrate the arithmetic operators

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

Problem Solution:

Here, we will create three integer variables and perform all arithmetic operations, and print results.

Program/Source Code:

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

// Rust program to demonstrate the 
// arithmetic operators

fn main() {
    let mut num1:i32=27;
    let mut num2:i32=5;
    let mut num3:i32=0;
    
    // '+' operator
    num3=num1+num2;
    println!("Addition is: {}",num3);

    // '-' operator
    num3=num1-num2;
    println!("Subtraction is: {}",num3);

    // '*' operator
    num3=num1*num2;
    println!("Multiplication is: {}",num3);

    // '/' operator
    num3=num1/num2;
    println!("Division is: {}",num3);

    // '%' operator
    num3=num1%num2;
    println!("Remainder is: {}",num3);    
}

Output:

Addition is: 32
Subtraction is: 22
Multiplication is: 135
Division is: 5
Remainder is: 2

Explanation:

Here, we created three integer variables num1, num2, and num3 that are initialized with 27, 5, 0 respectively. Then we performed all arithmetic operations 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.