Posted on by Kalkicode
Code Conversion

Convert hectare to square yard

Units of measurement play a crucial role in everyday life and various fields. The hectare (ha) is a unit of area commonly used to measure large land areas, especially in agriculture and urban planning. The square yard (yd²) is another unit of area that's often used, especially in the United States and some other countries. Converting between these two units allows us to express land areas in terms of a unit that might be more familiar or relevant in a specific context.

Problem Statement and Description

The problem at hand is to convert an area given in hectares to its equivalent value in square yards. The formula to convert from hectares to square yards is (hectare * 11960), where 11960 is the conversion factor that relates a hectare to square yards. This formula takes the given area in hectares, multiplies it by the conversion factor, and provides the area in square yards.

Example

Let's consider an example to better understand the problem. Suppose we have an area of 2.5 hectares that we want to convert to square yards. Using the formula:

Square Yard = Hectare * 11960
    Square Yard = 2.5 * 11960
    Square Yard = 29900

So, 2.5 hectares is equivalent to 29900 square yards.

Idea to Solve the Problem

To solve this problem, we need to develop a program that takes an area in hectares as input, applies the conversion formula, and outputs the equivalent area in square yards. We will define a function to perform the conversion, and the main program will call this function for different test cases.

Pseudocode

Here's the pseudocode for the program:

function hectare_to_square_yard(hectare):
        square_yard = hectare * 11960
        return square_yard
main:
    hectare_to_square_yard(1)
    hectare_to_square_yard(25.6)
    hectare_to_square_yard(70)

Algorithm Explanation

  1. Define the hectare_to_square_yard function that takes a parameter hectare.
  2. Inside the function, calculate the equivalent area in square yards using the formula hectare * 11960.
  3. Return the calculated area in square yards.
  4. In the main program, call the hectare_to_square_yard function with different test cases: 1, 25.6, and 70.
  5. Print the results.

Code Solution

//C Program 
//Convert hectare to square yard
#include <stdio.h>
 //Find the square yard of given hectare
void hectare_to_square_yard(double hectare)
{
	// Calculate square yard by using hectare
	// Formula : (hectare * 11960 )
	double square_yard = (hectare * 11960);
	printf("[%lf] Hectare is approximate equal to [%lf] Square Yard \n", hectare, square_yard);
}
int main()
{
	//Simple test
	hectare_to_square_yard(1);
	hectare_to_square_yard(25.6);
	hectare_to_square_yard(70);
	return 0;
}

Output

[1.000000] Hectare is approximate equal to [11960.000000] Square Yard
[25.600000] Hectare is approximate equal to [306176.000000] Square Yard
[70.000000] Hectare is approximate equal to [837200.000000] Square Yard
/*
Java program
Convert hectare to square yard
*/
class MyMath
{
	//Find the square yard of given hectare
	void hectare_to_square_yard(double hectare)
	{
		// Calculate square yard by using hectare
		// Formula : (hectare * 11960 )
		double square_yard = (hectare * 11960);
		System.out.print("[" + hectare + "] Hectare is approximate equal to [" + square_yard + "] Square Yard \n");
	}
	public static void main(String[] args)
	{
		MyMath obj = new MyMath();
		//Simple test
		obj.hectare_to_square_yard(1);
		obj.hectare_to_square_yard(25.6);
		obj.hectare_to_square_yard(70);
	}
}

Output

[1.0] Hectare is approximate equal to [11960.0] Square Yard
[25.6] Hectare is approximate equal to [306176.0] Square Yard
[70.0] Hectare is approximate equal to [837200.0] Square Yard
//Include header file
#include <iostream>

using namespace std;
/*
C++ program
Convert hectare to square yard
*/
class MyMath
{
	public:
		//Find the square yard of given hectare
		void hectare_to_square_yard(double hectare)
		{
			// Calculate square yard by using hectare
			// Formula : (hectare * 11960 )
			double square_yard = (hectare * 11960);
			cout << "[" << hectare << "] Hectare is approximate equal to [" << square_yard << "] Square Yard \n";
		}
};
int main()
{
	MyMath obj = MyMath();
	//Simple test
	obj.hectare_to_square_yard(1);
	obj.hectare_to_square_yard(25.6);
	obj.hectare_to_square_yard(70);
	return 0;
}

Output

[1] Hectare is approximate equal to [11960] Square Yard
[25.6] Hectare is approximate equal to [306176] Square Yard
[70] Hectare is approximate equal to [837200] Square Yard
/*
C# program
Convert hectare to square yard
*/
//Include namespace system
using System;
class MyMath
{
	//Find the square yard of given hectare
	void hectare_to_square_yard(double hectare)
	{
		// Calculate square yard by using hectare
		// Formula : (hectare * 11960 )
		double square_yard = (hectare * 11960);
		Console.Write("[" + hectare + "] Hectare is approximate equal to [" + square_yard + "] Square Yard \n");
	}
	public static void Main(String[] args)
	{
		MyMath obj = new MyMath();
		//Simple test
		obj.hectare_to_square_yard(1);
		obj.hectare_to_square_yard(25.6);
		obj.hectare_to_square_yard(70);
	}
}

Output

[1] Hectare is approximate equal to [11960] Square Yard
[25.6] Hectare is approximate equal to [306176] Square Yard
[70] Hectare is approximate equal to [837200] Square Yard
<?php
/*
Php program
Convert hectare to square yard
*/
class MyMath
{
	//Find the square yard of given hectare
	function hectare_to_square_yard($hectare)
	{
		// Calculate square yard by using hectare
		// Formula : (hectare * 11960 )
		$square_yard = ($hectare * 11960);
		echo "[". $hectare ."] Hectare is approximate equal to [". $square_yard ."] Square Yard \n";
	}
}

function main()
{
	$obj = new MyMath();
	//Simple test
	$obj->hectare_to_square_yard(1);
	$obj->hectare_to_square_yard(25.6);
	$obj->hectare_to_square_yard(70);
}
main();

Output

[1] Hectare is approximate equal to [11960] Square Yard
[25.6] Hectare is approximate equal to [306176] Square Yard
[70] Hectare is approximate equal to [837200] Square Yard
/*
Node Js program
Convert hectare to square yard
*/
class MyMath
{
	//Find the square yard of given hectare
	hectare_to_square_yard(hectare)
	{
		// Calculate square yard by using hectare
		// Formula : (hectare * 11960 )
		var square_yard = (hectare * 11960);
		process.stdout.write("[" + hectare + "] Hectare is approximate equal to [" + square_yard + "] Square Yard \n");
	}
}

function main()
{
	var obj = new MyMath();
	//Simple test
	obj.hectare_to_square_yard(1);
	obj.hectare_to_square_yard(25.6);
	obj.hectare_to_square_yard(70);
}
main();

Output

[1] Hectare is approximate equal to [11960] Square Yard
[25.6] Hectare is approximate equal to [306176] Square Yard
[70] Hectare is approximate equal to [837200] Square Yard
# Python 3 program
# Convert hectare to square yard

class MyMath :
	# Find the square yard of given hectare
	def hectare_to_square_yard(self, hectare) :
		#  Calculate square yard by using hectare
		#  Formula : (hectare * 11960 )
		square_yard = (hectare * 11960)
		print("[", hectare ,"] Hectare is approximate equal to [", square_yard ,"] Square Yard \n", end = "")
	

def main() :
	obj = MyMath()
	# Simple test
	obj.hectare_to_square_yard(1)
	obj.hectare_to_square_yard(25.6)
	obj.hectare_to_square_yard(70)

if __name__ == "__main__": main()

Output

[ 1 ] Hectare is approximate equal to [ 11960 ] Square Yard
[ 25.6 ] Hectare is approximate equal to [ 306176.0 ] Square Yard
[ 70 ] Hectare is approximate equal to [ 837200 ] Square Yard
# Ruby program
# Convert hectare to square yard

class MyMath

	# Find the square yard of given hectare
	def hectare_to_square_yard(hectare)
	
		#  Calculate square yard by using hectare
		#  Formula : (hectare * 11960 )
		square_yard = (hectare * 11960)
		print("[", hectare ,"] Hectare is approximate equal to [", square_yard ,"] Square Yard \n")
	end
end
def main()

	obj = MyMath.new()
	# Simple test
	obj.hectare_to_square_yard(1)
	obj.hectare_to_square_yard(25.6)
	obj.hectare_to_square_yard(70)
end
main()

Output

[1] Hectare is approximate equal to [11960] Square Yard 
[25.6] Hectare is approximate equal to [306176.0] Square Yard 
[70] Hectare is approximate equal to [837200] Square Yard 
/*
Scala program
Convert hectare to square yard
*/
class MyMath
{
	//Find the square yard of given hectare
	def hectare_to_square_yard(hectare: Double): Unit = {
		// Calculate square yard by using hectare
		// Formula : (hectare * 11960 )
		var square_yard: Double = (hectare * 11960);
		print("[" + hectare + "] Hectare is approximate equal to [" + square_yard + "] Square Yard \n");
	}
}
object Main
{
	def main(args: Array[String]): Unit = {
		var obj: MyMath = new MyMath();
		//Simple test
		obj.hectare_to_square_yard(1);
		obj.hectare_to_square_yard(25.6);
		obj.hectare_to_square_yard(70);
	}
}

Output

[1.0] Hectare is approximate equal to [11960.0] Square Yard
[25.6] Hectare is approximate equal to [306176.0] Square Yard
[70.0] Hectare is approximate equal to [837200.0] Square Yard
/*
Swift program
Convert hectare to square yard
*/
class MyMath
{
	//Find the square yard of given hectare
	func hectare_to_square_yard(_ hectare: Double)
	{
		// Calculate square yard by using hectare
		// Formula : (hectare * 11960 )
		let square_yard: Double = (hectare * 11960);
		print("[", hectare ,"] Hectare is approximate equal to [", square_yard ,"] Square Yard \n", terminator: "");
	}
}
func main()
{
	let obj: MyMath = MyMath();
	//Simple test
	obj.hectare_to_square_yard(1);
	obj.hectare_to_square_yard(25.6);
	obj.hectare_to_square_yard(70);
}
main();

Output

[ 1.0 ] Hectare is approximate equal to [ 11960.0 ] Square Yard
[ 25.6 ] Hectare is approximate equal to [ 306176.0 ] Square Yard
[ 70.0 ] Hectare is approximate equal to [ 837200.0 ] Square Yard

Time Complexity

Similar to the previous examples, the time complexity of this program is constant for each conversion. It involves basic multiplication, which takes a constant amount of time. Thus, the time complexity is O(1).

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