Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // THIS PROGRAM CASTS DIFFERING DATATYPES IN RUST
- fn main() {
- println!("\nBEGIN PROGRAM.\n");
- println!("\nHere are some stored answers.\n");
- // INITIAL DECLARATIONS
- let x1: u8 = 0;
- println!("\nFIRST ANSWER: {x1}");
- let x2: u16 = 256;
- println!("SECOND ANSWER: {x2}");
- let x3: u32 = 65536;
- println!("THIRD ANSWER: {x3}");
- let y1: i8 = -1;
- println!("FOURTH ANSWER: {y1}");
- let y2: i16 = -129;
- println!("FIFTH ANSWER: {y2}");
- let y3: i32 = -66000;
- println!("SIXTH ANSWER: {y3}\n");
- // CASTINGS BEFORE ADDITION
- let z1 = x1 as u32;
- let z2 = x2 as u32;
- let z3 = y1 as i32;
- let z4 = y2 as i32;
- let z_flash = z1 + z2 + x3;
- let z2_flash = z3 + z4 + y3;
- println!("\nThe sum of the first three values is {z_flash}.");
- println!("The sum of the second three values is {z2_flash}.\n");
- let box_1 = z_flash as i32;
- let box_2 = z2_flash as i32;
- let trailer = box_1 + box_2;
- println!("The sum of both groups is: {trailer}.\n");
- println!("\nEND PROGRAM.\n");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement