Link Search Menu Expand Document

Challenge: Find the Area of a Triangle

  • Problem Statement The task is to call the root function my_area that calculates the area of a triangle.

area of a traingle = 1/2∗base∗height

  • A method triangle_area() is defined within the module shapes.
  • The task is to complete the method
    • Implement root function.
    • Call the root function my_area from within the public function triangle_area().
    • Print the return value from the root function, i.e., area of the triangle


   x and y   

Note: Assume that base and height are passed to the function my_public_function


The area of a triangle

 float value

Sample Input

   x = 3, y = 4

Sample Output


Coding Exercise

mod shapes{
  pub fn triangle_area(base : i32, height : i32) {
      // call the root function 'my_area' and print the return value

Good luck!🤞