In this challenge, you will implement a function calculate_area
that computes the area of a rectangle using a given width
and height
. The purpose of this exercise is to practice variable declaration.
You are provided with a helper function prints_values
that takes two parameters, width
and height
, and prints their values. Your task is to call this helper function inside calculate_area
and ensure that the printed values are correct.
The calculate_area
function should:
width
and height
.prints_values
function to display the values of the width
and height
.width
and height
.Do not modify the prints_values
function.
Note: While it is possible to solve the challenge and pass the tests without explicitly declaring variables (e.g., by directly passing values to
prints_values
or using expressions inline), we recommend you practice declaring variables using thelet
keyword.
let
keyword to declare variables in Rust.prints_values
function is invoked with the correct arguments.width
and height
.pub fn calculate_area() -> u32 { // TODO: Implement the function here // 1. Declare a variable named width // 2. Declare a variable named height // 3. Run the `prints_values` function with the width and height variables // 4. Return the multiplication of width and height let width : u32 = 40; let height : u32 = 10; prints_values(width, height); let area : u32 = width * height; area}// WARNING: Do not modify this functionpub fn prints_values(width: u32, height: u32) { println!("The width is: {}", width); println!("The height is: {}", height);}
pub fn calculate_area() -> u32 { // TODO: Implement the function here // 1. Declare a variable named width let width: u32 = 100; // 2. Declare a variable named height let height: u32 = 100; // 3. Run the `prints_values` function with the width and height variables prints_values(width, height); // 4. Return the multiplication of width and height return width * height;}// WARNING: Do not modify this functionpub fn prints_values(width: u32, height: u32) { println!("The width is: {}", width); println!("The height is: {}", height);}
pub fn calculate_area() -> u32 { // TODO: Implement the function here // 1. Declare a variable named width let width: u32 = 10; // 2. Declare a variable named height let height: u32 = 12; // 3. Run the `prints_values` function with the width and height variables prints_values(width, height); // 4. Return the multiplication of width and height width * height}// WARNING: Do not modify this functionpub fn prints_values(width: u32, height: u32) { println!("The width is: {}", width); println!("The height is: {}", height);}
pub fn calculate_area() -> u32 { // TODO: Implement the function here // 1. Declare a variable named width let width: u32 = 12; // 2. Declare a variable named height let height: u32 = 20; // 3. Run the `prints_values` function with the width and height variables // 4. Return the multiplication of width and height prints_values(width, height); width * height}// WARNING: Do not modify this functionpub fn prints_values(width: u32, height: u32) { println!("The width is: {}", width); println!("The height is: {}", height);}
pub fn calculate_area() -> u32 { // TODO: Implement the function here // 1. Declare a variable named width // 2. Declare a variable named height // 3. Run the `prints_values` function with the width and height variables // 4. Return the multiplication of width and height let width:u32 = 5; let height:u32 = 5; prints_values(width,height); return width * height}// WARNING: Do not modify this functionpub fn prints_values(width: u32, height: u32) { println!("The width is: {}", width); println!("The height is: {}", height);}
pub fn calculate_area() -> u32 { // TODO: Implement the function here // 1. Declare a variable named width let width : u32 = 100; // 2. Declare a variable named height let height:u32 = 20; // 3. Run the `prints_values` function with the width and height variables prints_values(width , height); // 4. Return the multiplication of width and height return width * height;}// WARNING: Do not modify this functionpub fn prints_values(width: u32, height: u32) { println!("The width is: {}", width); println!("The height is: {}", height);}
pub fn calculate_area() -> u32 { // TODO: Implement the function here // 1. Declare a variable named width // 2. Declare a variable named height // 3. Run the `prints_values` function with the width and height variables // 4. Return the multiplication of width and height let width : u32 = 1; let height : u32 = 1; prints_values(width,height); return width*height;}// WARNING: Do not modify this functionpub fn prints_values(width: u32, height: u32) { println!("The width is: {}", width); println!("The height is: {}", height);}
pub fn calculate_area() -> u32 { // TODO: Implement the function here // 1. Declare a variable named width // 2. Declare a variable named height // 3. Run the `prints_values` function with the width and height variables // 4. Return the multiplication of width and height let width: u32 = 10_u32; let height: u32 = 10_u32; prints_values(width, height); return width * height;}// WARNING: Do not modify this functionpub fn prints_values(width: u32, height: u32) { println!("The width is: {}", width); println!("The height is: {}", height);}
pub fn calculate_area() -> u32 { // TODO: Implement the function here // 1. Declare a variable named width // 2. Declare a variable named height // 3. Run the `prints_values` function with the width and height variables // 4. Return the multiplication of width and height let width =100; let height= 200; prints_values(width, height); width*height}// WARNING: Do not modify this functionpub fn prints_values(width: u32, height: u32) { println!("The width is: {}", width); println!("The height is: {}", height);}
pub fn calculate_area() -> u32 { // TODO: Implement the function here // 1. Declare a variable named width // 2. Declare a variable named height // 3. Run the `prints_values` function with the width and height variables // 4. Return the multiplication of width and height let width = 100; let height = 200; prints_values(width, height); width * height}// WARNING: Do not modify this functionpub fn prints_values(width: u32, height: u32) { println!("The width is: {}", width); println!("The height is: {}", height);}
pub fn calculate_area() -> u32 { // TODO: Implement the function here // 1. Declare a variable named width // 2. Declare a variable named height // 3. Run the `prints_values` function with the width and height variables // 4. Return the multiplication of width and height let width: u32 = 8; let height: u32 = 8; prints_values(width, height); return width*height;}// WARNING: Do not modify this functionpub fn prints_values(width: u32, height: u32) { println!("The width is: {}", width); println!("The height is: {}", height);}
pub fn calculate_area() -> u32 { // TODO: Implement the function here // 1. Declare a variable named width // 2. Declare a variable named height // 3. Run the `prints_values` function with the width and height variables // 4. Return the multiplication of width and height let width : u32 = 10; let height : u32 = 5; prints_values(width, height); width * height}// WARNING: Do not modify this functionpub fn prints_values(width: u32, height: u32) { println!("The width is: {}", width); println!("The height is: {}", height);}
pub fn calculate_area() -> u32 { // TODO: Implement the function here // 1. Declare a variable named width // 2. Declare a variable named height // 3. Run the `prints_values` function with the width and height variables // 4. Return the multiplication of width and height let width: u32 = 50; let height: u32 = 50; prints_values(width, height); return width * height;}// WARNING: Do not modify this functionpub fn prints_values(width: u32, height: u32) { println!("The width is: {}", width); println!("The height is: {}", height);}
pub fn calculate_area() -> u32 { // TODO: Implement the function here // 1. Declare a variable named width // 2. Declare a variable named height // 3. Run the `prints_values` function with the width and height variables // 4. Return the multiplication of width and height let width: u32 = 10; let height: u32 = 20; prints_values(width, height); width * height}// WARNING: Do not modify this functionpub fn prints_values(width: u32, height: u32) { println!("The width is: {}", width); println!("The height is: {}", height);}
pub fn calculate_area() -> u32 { // TODO: Implement the function here // 1. Declare a variable named width // 2. Declare a variable named height // 3. Run the `prints_values` function with the width and height variables // 4. Return the multiplication of width and height let width = 10; let height = 20; prints_values(width, height); return width*height; }// WARNING: Do not modify this functionpub fn prints_values(width: u32, height: u32) { println!("The width is: {}", width); println!("The height is: {}", height);}
pub fn calculate_area() -> u32 { // TODO: Implement the function here // 1. Declare a variable named width let width = 1; // 2. Declare a variable named height let height = 2; // 3. Run the `prints_values` function with the width and height variables prints_values(width, height); // 4. Return the multiplication of width and height width * height}// WARNING: Do not modify this functionpub fn prints_values(width: u32, height: u32) { println!("The width is: {}", width); println!("The height is: {}", height);}
pub fn calculate_area() -> u32 { let width = 1; let height = 10; prints_values(width, height); return width * height;}// WARNING: Do not modify this functionpub fn prints_values(width: u32, height: u32) { println!("The width is: {}", width); println!("The height is: {}", height);}
pub fn calculate_area() -> u32 { // TODO: Implement the function here let width = 10; // 1. Declare a variable named width let height = 20; // 2. Declare a variable named height prints_values(width, height); // 3. Run the `prints_values` function with the width and height variables return width * height; // 4. Return the multiplication of width and height}// WARNING: Do not modify this functionpub fn prints_values(width: u32, height: u32) { println!("The width is: {}", width); println!("The height is: {}", height);}
pub fn calculate_area() -> u32 { // TODO: Implement the function here // 1. Declare a variable named width // 2. Declare a variable named height // 3. Run the `prints_values` function with the width and height variables // 4. Return the multiplication of width and height let width = 3; let height = 3; prints_values(width, height); width*height}// WARNING: Do not modify this functionpub fn prints_values(width: u32, height: u32) { println!("The width is: {}", width); println!("The height is: {}", height);}
pub fn calculate_area() -> u32 { // TODO: Implement the function here // 1. Declare a variable named width // 2. Declare a variable named height // 3. Run the `prints_values` function with the width and height variables // 4. Return the multiplication of width and height let width: u32 = 2; let height: u32 = 3; prints_values(width, height); width * height}// WARNING: Do not modify this functionpub fn prints_values(width: u32, height: u32) { println!("The width is: {}", width); println!("The height is: {}", height);}
pub fn calculate_area() -> u32 { // TODO: Implement the function here // 1. Declare a variable named width // 2. Declare a variable named height // 3. Run the `prints_values` function with the width and height variables // 4. Return the multiplication of width and height let width: u32 = 10; let height: u32 = 10; prints_values(width, height); return width * height;}// WARNING: Do not modify this functionpub fn prints_values(width: u32, height: u32) { println!("The width is: {}", width); println!("The height is: {}", height);}
pub fn calculate_area() -> u32 { // TODO: Implement the function here // 1. Declare a variable named width // 2. Declare a variable named height // 3. Run the `prints_values` function with the width and height variables // 4. Return the multiplication of width and height let width = 1; let height = 2; prints_values(width, height); return 1 * 2}// WARNING: Do not modify this functionpub fn prints_values(width: u32, height: u32) { println!("The width is: {}", width); println!("The height is: {}", height);}
pub fn calculate_area() -> u32 { // TODO: Implement the function here // 1. Declare a variable named width let width: u32 = 10; // 2. Declare a variable named height let height: u32 = 5; // 3. Run the `prints_values` function with the width and height variables prints_values(width, height); // 4. Return the multiplication of width and height return width * height;}// WARNING: Do not modify this functionpub fn prints_values(width: u32, height: u32) { println!("The width is: {}", width); println!("The height is: {}", height);}
pub fn calculate_area() -> u32 { // TODO: Implement the function here // 1. Declare a variable named width // 2. Declare a variable named height // 3. Run the `prints_values` function with the width and height variables // 4. Return the multiplication of width and heightlet width:u32 = 10;let height:u32 = 20; prints_values(width, height); width * height}// WARNING: Do not modify this functionpub fn prints_values(width: u32, height: u32) { println!("The width is: {}", width); println!("The height is: {}", height);}
pub fn calculate_area() -> u32 { let width: u32 = 23; let height: u32 = 7; prints_values(width, height); // Ensure function exists width * height}// WARNING: Do not modify this functionpub fn prints_values(width: u32, height: u32) { println!("The width is: {}", width); println!("The height is: {}", height);}
pub fn calculate_area() -> u32 { let width: u32 = 300; let height: u32 = 100; prints_values(width, height); width * height // TODO: Implement the function here // 1. Declare a variable named width // 2. Declare a variable named height // 3. Run the `prints_values` function with the width and height variables // 4. Return the multiplication of width and height}// WARNING: Do not modify this functionpub fn prints_values(width: u32, height: u32) { println!("The width is: {}", width); println!("The height is: {}", height);}
pub fn calculate_area() -> u32 { // TODO: Implement the function here let width:u32 = 10; let height:u32 = 20; // 1. Declare a variable named width // 2. Declare a variable named height // 3. Run the `prints_values` function with the width and height variables prints_values(width,height); return width * height; // 4. Return the multiplication of width and height}// WARNING: Do not modify this functionpub fn prints_values(width: u32, height: u32) { println!("The width is: {}", width); println!("The height is: {}", height);}
pub fn calculate_area() -> u32 { // TODO: Implement the function here // 1. Declare a variable named width let width: u32 = 32; // 2. Declare a variable named height let height: u32 = 32; prints_values(width, height); width * height // 3. Run the `prints_values` function with the width and height variables // 4. Return the multiplication of width and height}// WARNING: Do not modify this functionpub fn prints_values(width: u32, height: u32) { println!("The width is: {}", width); println!("The height is: {}", height);}
pub fn calculate_area() -> u32 { // TODO: Implement the function here // 1. Declare a variable named width let width: u32 = 32; // 2. Declare a variable named height let height: u32 = 32; prints_values(width, height); let sum: u32 = width * height; sum // 3. Run the `prints_values` function with the width and height variables // 4. Return the multiplication of width and height}// WARNING: Do not modify this functionpub fn prints_values(width: u32, height: u32) { println!("The width is: {}", width); println!("The height is: {}", height);}
pub fn calculate_area() -> u32 { let width: u32 = 21; let height: u32 = 34; prints_values(width, height); let multiplication = height * width; println!("The result of this multiplication is: {}", multiplication); multiplication}pub fn prints_values(width: u32, height: u32) { println!("The width is: {}", width); println!("The height is: {}", height);}
pub fn calculate_area() -> u32 { let width: u32 = 10; let height: u32 = 5; prints_values(width, height); width * height // TODO: Implement the function here // 1. Declare a variable named width // 2. Declare a variable named height // 3. Run the `prints_values` function with the width and height variables // 4. Return the multiplication of width and height}// WARNING: Do not modify this functionpub fn prints_values(width: u32, height: u32) { println!("The width is: {}", width); println!("The height is: {}", height);}
pub fn calculate_area() -> u32 { let width = 10; let height = 5; prints_values(width, height); width * height}// WARNING: Do not modify this functionpub fn prints_values(width: u32, height: u32) { println!("The width is: {}", width); println!("The height is: {}", height);}
pub fn calculate_area() -> u32 { // TODO: Implement the function here // 1. Declare a variable named width // 2. Declare a variable named height // 3. Run the `prints_values` function with the width and height variables // 4. Return the multiplication of width and height let width = 5; let height = 15; prints_values(width, height); width*height}// WARNING: Do not modify this functionpub fn prints_values(width: u32, height: u32) { println!("The width is: {}", width); println!("The height is: {}", height);}
pub fn calculate_area() -> u32 { // TODO: Implement the function here // 1. Declare a variable named width // 2. Declare a variable named height // 3. Run the `prints_values` function with the width and height variables // 4. Return the multiplication of width and height let width = 10; let height = 20; prints_values(width, height); return 10 * 20;}// WARNING: Do not modify this functionpub fn prints_values(width: u32, height: u32) { println!("The width is: {}", width); println!("The height is: {}", height);}
pub fn calculate_area() -> u32 { // TODO: Implement the function here // 1. Declare a variable named width // 2. Declare a variable named height // 3. Run the `prints_values` function with the width and height variables // 4. Return the multiplication of width and height let width = 5; // 这里可以设置具体的宽度值 // 2. Declare a variable named height let height = 10; // 这里可以设置具 prints_values(width, height); width * height}// WARNING: Do not modify this functionpub fn prints_values(width: u32, height: u32) { println!("The width is: {}", width); println!("The height is: {}", height);}
pub fn calculate_area() -> u32 { // TODO: Implement the function here // 1. Declare a variable named width // 2. Declare a variable named height // 3. Run the `prints_values` function with the width and height variables // 4. Return the multiplication of width and height let width: u32 = 30; let height: u32= 40; prints_values(width, height); width * height}// WARNING: Do not modify this functionpub fn prints_values(width: u32, height: u32) { println!("The width is: {}", width); println!("The height is: {}", height);}
pub fn calculate_area() -> u32 { // TODO: Implement the function here // 1. Declare a variable named width // 2. Declare a variable named height // 3. Run the `prints_values` function with the width and height variables // 4. Return the multiplication of width and height let width = 5; let height = 5; prints_values(width, height); return width * height;}// WARNING: Do not modify this functionpub fn prints_values(width: u32, height: u32) { println!("The width is: {}", width); println!("The height is: {}", height);}
pub fn calculate_area() -> u32 { let width: u32 = 25; let height: u32 = 32; prints_values(width, height); width * height // TODO: Implement the function here // 1. Declare a variable named width // 2. Declare a variable named height // 3. Run the `prints_values` function with the width and height variables // 4. Return the multiplication of width and height}// WARNING: Do not modify this functionpub fn prints_values(width: u32, height: u32) { println!("The width is: {}", width); println!("The height is: {}", height);}
pub fn calculate_area() -> u32 { // TODO: Implement the function here // 1. Declare a variable named width // 2. Declare a variable named height // 3. Run the `prints_values` function with the width and height variables // 4. Return the multiplication of width and height let width: u32 = 1; let height: u32 = 1; prints_values(width, height); width*height}// WARNING: Do not modify this functionpub fn prints_values(width: u32, height: u32) { println!("The width is: {}", width); println!("The height is: {}", height);}
pub fn calculate_area() -> u32 { // TODO: Implement the function here // 1. Declare a variable named width // 2. Declare a variable named height // 3. Run the `prints_values` function with the width and height variables // 4. Return the multiplication of width and height let width: u32 = 5; let height: u32 = 6; prints_values(width, height); width * height}// WARNING: Do not modify this functionpub fn prints_values(width: u32, height: u32) { println!("The width is: {}", width); println!("The height is: {}", height);}
pub fn calculate_area() -> u32 { // TODO: Implement the function here // 1. Declare a variable named width // 2. Declare a variable named height // 3. Run the `prints_values` function with the width and height variables // 4. Return the multiplication of width and height let width: u32 = 5; let height: u32 = 6; prints_values(width, height); width * height}// WARNING: Do not modify this functionpub fn prints_values(width: u32, height: u32) { println!("The width is: {}", width); println!("The height is: {}", height);}
pub fn calculate_area() -> u32 { // TODO: Implement the function here // 1. Declare a variable named width // 2. Declare a variable named height // 3. Run the `prints_values` function with the width and height variables // 4. Return the multiplication of width and height let width = 100; let height = 100; prints_values(width, height); width * height}// WARNING: Do not modify this functionpub fn prints_values(width: u32, height: u32) { println!("The width is: {}", width); println!("The height is: {}", height);}
pub fn calculate_area() -> u32 { // TODO: Implement the function here // 1. Declare a variable named width // 2. Declare a variable named height // 3. Run the `prints_values` function with the width and height variables // 4. Return the multiplication of width and height let width = 5; let height = 6; prints_values(width, height); return width * height;}// WARNING: Do not modify this functionpub fn prints_values(width: u32, height: u32) { println!("The width is: {}", width); println!("The height is: {}", height);}
pub fn calculate_area() -> u32 { // TODO: Implement the function here // 1. Declare a variable named width // 2. Declare a variable named height // 3. Run the `prints_values` function with the width and height variables // 4. Return the multiplication of width and height let width:u32 = 15; let height:u32 = 15; prints_values(width,height); width*height}// WARNING: Do not modify this functionpub fn prints_values(width: u32, height: u32) { println!("The width is: {}", width); println!("The height is: {}", height);}
pub fn calculate_area() -> u32 { let width: u32 = 12; let height: u32 = 12; prints_values(width, height); width * height}// WARNING: Do not modify this functionpub fn prints_values(width: u32, height: u32) { println!("The width is: {}", width); println!("The height is: {}", height);}
pub fn calculate_area() -> u32 { let width = 10; let height = 10; prints_values(width, height); width * height}// WARNING: Do not modify this functionpub fn prints_values(width: u32, height: u32) { println!("The width is: {}", width); println!("The height is: {}", height);}
pub fn calculate_area() -> u32 { // TODO: Implement the function here // 1. Declare a variable named width // 2. Declare a variable named height // 3. Run the `prints_values` function with the width and height variables // 4. Return the multiplication of width and height let width = 2; let height = 3; prints_values(width, height); return width * height;}// WARNING: Do not modify this functionpub fn prints_values(width: u32, height: u32) { println!("The width is: {}", width); println!("The height is: {}", height);}
pub fn calculate_area() -> u32 { // TODO: Implement the function here // 1. Declare a variable named width // 2. Declare a variable named height // 3. Run the `prints_values` function with the width and height variables // 4. Return the multiplication of width and height let width: u32 = 10; let height: u32 = 20; prints_values(width, height); width * height}// WARNING: Do not modify this functionpub fn prints_values(width: u32, height: u32) { println!("The width is: {}", width); println!("The height is: {}", height);}
pub fn calculate_area() -> u32 { let width = 10; let height = 10; prints_values(width, height); return width * height;}// WARNING: Do not modify this functionpub fn prints_values(width: u32, height: u32) { println!("The width is: {}", width); println!("The height is: {}", height);}
pub fn calculate_area() -> u32 { // TODO: Implement the function here // 1. Declare a variable named width // 2. Declare a variable named height // 3. Run the `prints_values` function with the width and height variables // 4. Return the multiplication of width and height let width = 65; let height = 54; prints_values(width, height); width * height}// WARNING: Do not modify this functionpub fn prints_values(width: u32, height: u32) { println!("The width is: {}", width); println!("The height is: {}", height);}