Skip to main content

Convert the square metre to square yard

Converting measurements between different units is a common task in various fields, including construction, engineering, and everyday activities. One such conversion is from square meters to square yards. Square meters and square yards are units of area, and converting between them is useful when working with measurements that are provided in one unit but need to be represented in another.

Problem Statement

Given an area in square meters, the task is to convert it into the equivalent area in square yards. This conversion involves translating the given measurement from one unit to another using a conversion factor.

Example

Consider the first test case from your code:

  • Area in square meters: 1

We want to convert this area to square yards.

Idea to Solve the Problem

The conversion from square meters to square yards involves multiplying the given area in square meters by a conversion factor. The conversion factor between square meters and square yards is approximately 1.196.

Pseudocode

square_metre_to_square_yard(square_metre):
    square_yard = square_metre * 1.196
    display square_metre, square_yard

Algorithm Explanation

  1. The square_metre_to_square_yard function takes an area in square meters as input.
  2. It multiplies the input value by the conversion factor 1.196 to calculate the equivalent area in square yards.
  3. The calculated area in square yards is then displayed along with the original area in square meters.

Program Solution

//C Program 
//Convert the square metre to square yard
#include <stdio.h>

//Find the square metre of given square yard
void square_metre_to_square_yard(double square_metre)
{
	// Formula : (Square Metre * 1.196)
	// Calculate square yard 
	double square_yard = (square_metre * 1.196);
	//Display result
	printf("Square Metre :  %lf  Square Yard : %lf\n", square_metre, square_yard);
}
int main()
{
	//Simple test
	square_metre_to_square_yard(1);
	square_metre_to_square_yard(12.7);
	square_metre_to_square_yard(21);
	return 0;
}

Output

Square Metre :  1.000000  Square Yard : 1.196000
Square Metre :  12.700000  Square Yard : 15.189200
Square Metre :  21.000000  Square Yard : 25.116000
/*
Java program
Convert the square metre to square yard
*/
class MyMath
{
	//Find the square metre of given square yard
	public void square_metre_to_square_yard(double square_metre)
	{
		// Formula : (Square Metre * 1.196)
		// Calculate square yard 
		double square_yard = (square_metre * 1.196);
		System.out.print("Square Metre : " + square_metre + " Square Yard : " + square_yard + "\n");
	}
	public static void main(String[] args)
	{
		MyMath obj = new MyMath();
		//Simple test
		obj.square_metre_to_square_yard(1);
		obj.square_metre_to_square_yard(12.7);
		obj.square_metre_to_square_yard(21);
	}
}

Output

Square Metre : 1.0 Square Yard : 1.196
Square Metre : 12.7 Square Yard : 15.189199999999998
Square Metre : 21.0 Square Yard : 25.116
/*
C++ program
Convert the square metre to square yard
*/
#include<iostream>

using namespace std;
class MyMath
{
	public:
		//Find the square metre of given square yard
		void square_metre_to_square_yard(double square_metre)
		{
			// Formula : (Square Metre * 1.196)
			// Calculate square yard 
			double square_yard = (square_metre * 1.196);
			cout << "Square Metre : " << square_metre << " Square Yard : " << square_yard << "\n";
		}
};
int main()
{
	MyMath obj ;
	//Simple test
	obj.square_metre_to_square_yard(1);
	obj.square_metre_to_square_yard(12.7);
	obj.square_metre_to_square_yard(21);
	return 0;
}

Output

Square Metre : 1 Square Yard : 1.196
Square Metre : 12.7 Square Yard : 15.1892
Square Metre : 21 Square Yard : 25.116
/*
C# program
Convert the square metre to square yard
*/
using System;
class MyMath
{
	//Find the square metre of given square yard
	public void square_metre_to_square_yard(double square_metre)
	{
		// Formula : (Square Metre * 1.196)
		// Calculate square yard 
		double square_yard = (square_metre * 1.196);
		Console.Write("Square Metre : " + square_metre + " Square Yard : " + square_yard + "\n");
	}
	public static void Main(String[] args)
	{
		MyMath obj = new MyMath();
		//Simple test
		obj.square_metre_to_square_yard(1);
		obj.square_metre_to_square_yard(12.7);
		obj.square_metre_to_square_yard(21);
	}
}

Output

Square Metre : 1 Square Yard : 1.196
Square Metre : 12.7 Square Yard : 15.1892
Square Metre : 21 Square Yard : 25.116
<?php
/*
Php program
Convert the square metre to square yard
*/
class MyMath
{
	//Find the square metre of given square yard
	public	function square_metre_to_square_yard($square_metre)
	{
		// Formula : (Square Metre * 1.196)
		// Calculate square yard 
		$square_yard = ($square_metre * 1.196);
		echo "Square Metre : ". $square_metre ." Square Yard : ". $square_yard ."\n";
	}
}

function main()
{
	$obj = new MyMath();
	//Simple test
	$obj->square_metre_to_square_yard(1);
	$obj->square_metre_to_square_yard(12.7);
	$obj->square_metre_to_square_yard(21);
}
main();

Output

Square Metre : 1 Square Yard : 1.196
Square Metre : 12.7 Square Yard : 15.1892
Square Metre : 21 Square Yard : 25.116
/*
Node Js program
Convert the square metre to square yard
*/
class MyMath
{
	//Find the square metre of given square yard
	square_metre_to_square_yard(square_metre)
	{
		// Formula : (Square Metre * 1.196)
		// Calculate square yard 
		var square_yard = (square_metre * 1.196);
		process.stdout.write("Square Metre : " + square_metre + " Square Yard : " + square_yard + "\n");
	}
}

function main()
{
	var obj = new MyMath();
	//Simple test
	obj.square_metre_to_square_yard(1);
	obj.square_metre_to_square_yard(12.7);
	obj.square_metre_to_square_yard(21);
}
main();

Output

Square Metre : 1 Square Yard : 1.196
Square Metre : 12.7 Square Yard : 15.189199999999998
Square Metre : 21 Square Yard : 25.116
# Python 3 program
# Convert the square metre to square yard

class MyMath :
	# Find the square metre of given square yard
	def square_metre_to_square_yard(self, square_metre) :
		#  Formula : (Square Metre * 1.196)
		#  Calculate square yard 
		square_yard = (square_metre * 1.196)
		print("Square Metre : ", square_metre ," Square Yard : ", square_yard ,"\n", end = "")
	

def main() :
	obj = MyMath()
	# Simple test
	obj.square_metre_to_square_yard(1)
	obj.square_metre_to_square_yard(12.7)
	obj.square_metre_to_square_yard(21)

if __name__ == "__main__": main()

Output

Square Metre :  1  Square Yard :  1.196
Square Metre :  12.7  Square Yard :  15.189199999999998
Square Metre :  21  Square Yard :  25.116
# Ruby program
# Convert the square metre to square yard

class MyMath

	# Find the square metre of given square yard
	def square_metre_to_square_yard(square_metre)
	
		#  Formula : (Square Metre * 1.196)
		#  Calculate square yard 
		square_yard = (square_metre * 1.196)
		print("Square Metre : ", square_metre ," Square Yard : ", square_yard ,"\n")
	end
end
def main()

	obj = MyMath.new()
	# Simple test
	obj.square_metre_to_square_yard(1)
	obj.square_metre_to_square_yard(12.7)
	obj.square_metre_to_square_yard(21)
end
main()

Output

Square Metre : 1 Square Yard : 1.196
Square Metre : 12.7 Square Yard : 15.189199999999998
Square Metre : 21 Square Yard : 25.116
/*
Scala program
Convert the square metre to square yard
*/
class MyMath
{
	//Find the square metre of given square yard
	def square_metre_to_square_yard(square_metre: Double): Unit = {
		// Formula : (Square Metre * 1.196)
		// Calculate square yard 
		var square_yard: Double = (square_metre * 1.196);
		print("Square Metre : " + square_metre + " Square Yard : " + square_yard + "\n");
	}
}
object Main
{
	def main(args: Array[String]): Unit = {
		var obj: MyMath = new MyMath();
		//Simple test
		obj.square_metre_to_square_yard(1);
		obj.square_metre_to_square_yard(12.7);
		obj.square_metre_to_square_yard(21);
	}
}

Output

Square Metre : 1.0 Square Yard : 1.196
Square Metre : 12.7 Square Yard : 15.189199999999998
Square Metre : 21.0 Square Yard : 25.116
/*
Swift program
Convert the square metre to square yard
*/
class MyMath
{
	//Find the square metre of given square yard
	func square_metre_to_square_yard(_ square_metre: Double)
	{
		// Formula : (Square Metre * 1.196)
		// Calculate square yard 
		let square_yard: Double = (square_metre * 1.196);
		print("Square Metre : ", square_metre ," Square Yard : ", square_yard ,"\n", terminator: "");
	}
}
func main()
{
	let obj: MyMath = MyMath();
	//Simple test
	obj.square_metre_to_square_yard(1);
	obj.square_metre_to_square_yard(12.7);
	obj.square_metre_to_square_yard(21);
}
main();

Output

Square Metre :  1.0  Square Yard :  1.196
Square Metre :  12.7  Square Yard :  15.1892
Square Metre :  21.0  Square Yard :  25.116

Resultant Output Explanation

For the first test case (1 square meter):

  • Area in square meters: 1
  • Equivalent area in square yards: 1.196

For the second test case (12.7 square meters):

  • Area in square meters: 12.7
  • Equivalent area in square yards: 15.1892

For the third test case (21 square meters):

  • Area in square meters: 21
  • Equivalent area in square yards: 25.116

Time Complexity

The time complexity of this algorithm is constant, O(1), because the calculations involve only a fixed number of arithmetic operations regardless of the input area in square meters.





Comment

Please share your knowledge to improve code and content standard. Also submit your doubts, and test case. We improve by your feedback. We will try to resolve your query as soon as possible.

New Comment