Convert hectare to square kilometer
In various fields such as agriculture, urban planning, and land management, land areas are often measured in different units. Two common units used to measure land area are hectares and square kilometers. While hectares are commonly used to represent smaller land areas, square kilometers are used for larger areas. Sometimes, it becomes necessary to convert between these units to make meaningful comparisons or calculations. In this article, we will explore how to convert hectares to square kilometers and vice versa.
Problem Statement
Given the problem of converting hectares to square kilometers, we are asked to create a program that takes a value
in hectares as input and converts it to the corresponding value in square kilometers using the formula:
square kilometers = hectares / 100
.
Explanation with Suitable Example
To understand the concept better, let's consider an example. Suppose we have a land area of 500 hectares. To find out how many square kilometers this is equal to, we can use the conversion formula. By dividing 500 hectares by 100, we get 5 square kilometers. This means that 500 hectares is equivalent to 5 square kilometers.
Pseudocode
Before delving into the algorithm, let's outline the pseudocode for the conversion:
function hectare_to_square_km(hectare):
square_km = hectare / 100
return square_km
Algorithm with Explanation
The conversion algorithm is quite straightforward. Given the input value in hectares, the algorithm will calculate the corresponding value in square kilometers by dividing the hectares by 100.
- Start the algorithm.
- Accept the input value in hectares.
- Divide the input value by 100 to obtain the equivalent value in square kilometers.
- Return the calculated value.
- End the algorithm.
Resultant Output Explanation
Now, let's discuss the output produced by the provided code for a few test cases.
-
hectare_to_square_km(1);
In this case, we input 1 hectare. Applying the conversion formula:1 hectare / 100 = 0.01 square kilometers
. Thus, the output is[1.000000] Hectare is equal to [0.010000] Square Kilometer
. -
hectare_to_square_km(2021);
For an input of 2021 hectares, the conversion is:2021 hectares / 100 = 20.21 square kilometers
. Hence, the output is[2021.000000] Hectare is equal to [20.210000] Square Kilometer
. -
hectare_to_square_km(1500.6);
When given 1500.6 hectares, the result is:1500.6 hectares / 100 = 15.006 square kilometers
. Thus, the output is[1500.600000] Hectare is equal to [15.006000] Square Kilometer
.
Code Solution
//C Program
//Convert hectare to square kilometer
#include <stdio.h>
//Find the square kilometer of given hectare
void hectare_to_square_km(double hectare)
{
// Calculate square kilometer by using hectare
// Formula : (hectare / 100)
double square_km = (hectare / 100);
printf("[%lf] Hectare is equal to [%lf] Square Kilometer \n", hectare, square_km);
}
int main()
{
//Simple test
hectare_to_square_km(1);
hectare_to_square_km(2021);
hectare_to_square_km(1500.6);
return 0;
}
Output
[1.000000] Hectare is equal to [0.010000] Square Kilometer
[2021.000000] Hectare is equal to [20.210000] Square Kilometer
[1500.600000] Hectare is equal to [15.006000] Square Kilometer
/*
Java program
Convert hectare to square kilometer
*/
class MyMath
{ //Find the square kilometer of given hectare
public void hectare_to_square_km(double hectare)
{
// Calculate square kilometer by using hectare
// Formula : (hectare / 100)
double square_km = (hectare / 100);
System.out.print("[" + hectare + "] Hectare is equal to [" + square_km + "] Square Kilometer \n");
}
public static void main(String[] args)
{
MyMath obj = new MyMath();
//Simple test
obj.hectare_to_square_km(1);
obj.hectare_to_square_km(2021);
obj.hectare_to_square_km(1500.6);
}
}
Output
[1.0] Hectare is equal to [0.01] Square Kilometer
[2021.0] Hectare is equal to [20.21] Square Kilometer
[1500.6] Hectare is equal to [15.005999999999998] Square Kilometer
//Include header file
#include <iostream>
using namespace std;
/*
C++ program
Convert hectare to square kilometer
*/
class MyMath
{
public:
//Find the square kilometer of given hectare
void hectare_to_square_km(double hectare)
{
// Calculate square kilometer by using hectare
// Formula : (hectare / 100)
double square_km = (hectare / 100);
cout << "[" << hectare << "] Hectare is equal to [" << square_km << "] Square Kilometer \n";
}
};
int main()
{
MyMath obj = MyMath();
//Simple test
obj.hectare_to_square_km(1);
obj.hectare_to_square_km(2021);
obj.hectare_to_square_km(1500.6);
return 0;
}
Output
[1] Hectare is equal to [0.01] Square Kilometer
[2021] Hectare is equal to [20.21] Square Kilometer
[1500.6] Hectare is equal to [15.006] Square Kilometer
/*
C# program
Convert hectare to square kilometer
*/
//Include namespace system
using System;
class MyMath
{
//Find the square kilometer of given hectare
public void hectare_to_square_km(double hectare)
{
// Calculate square kilometer by using hectare
// Formula : (hectare / 100)
double square_km = (hectare / 100);
Console.Write("[" + hectare + "] Hectare is equal to [" + square_km + "] Square Kilometer \n");
}
public static void Main(String[] args)
{
MyMath obj = new MyMath();
//Simple test
obj.hectare_to_square_km(1);
obj.hectare_to_square_km(2021);
obj.hectare_to_square_km(1500.6);
}
}
Output
[1] Hectare is equal to [0.01] Square Kilometer
[2021] Hectare is equal to [20.21] Square Kilometer
[1500.6] Hectare is equal to [15.006] Square Kilometer
<?php
/*
Php program
Convert hectare to square kilometer
*/
class MyMath
{
//Find the square kilometer of given hectare
public function hectare_to_square_km($hectare)
{
// Calculate square kilometer by using hectare
// Formula : (hectare / 100)
$square_km = ($hectare / 100);
echo "[". $hectare ."] Hectare is equal to [". $square_km ."] Square Kilometer \n";
}
}
function main()
{
$obj = new MyMath();
//Simple test
$obj->hectare_to_square_km(1);
$obj->hectare_to_square_km(2021);
$obj->hectare_to_square_km(1500.6);
}
main();
Output
[1] Hectare is equal to [0.01] Square Kilometer
[2021] Hectare is equal to [20.21] Square Kilometer
[1500.6] Hectare is equal to [15.006] Square Kilometer
/*
Node Js program
Convert hectare to square kilometer
*/
class MyMath
{
//Find the square kilometer of given hectare
hectare_to_square_km(hectare)
{
// Calculate square kilometer by using hectare
// Formula : (hectare / 100)
var square_km = (hectare / 100);
process.stdout.write("[" + hectare + "] Hectare is equal to [" + square_km + "] Square Kilometer \n");
}
}
function main()
{
var obj = new MyMath();
//Simple test
obj.hectare_to_square_km(1);
obj.hectare_to_square_km(2021);
obj.hectare_to_square_km(1500.6);
}
main();
Output
[1] Hectare is equal to [0.01] Square Kilometer
[2021] Hectare is equal to [20.21] Square Kilometer
[1500.6] Hectare is equal to [15.005999999999998] Square Kilometer
# Python 3 program
# Convert hectare to square kilometer
class MyMath :
# Find the square kilometer of given hectare
def hectare_to_square_km(self, hectare) :
# Calculate square kilometer by using hectare
# Formula : (hectare / 100)
square_km = (hectare / 100)
print("[", hectare ,"] Hectare is equal to [", square_km ,"] Square Kilometer \n", end = "")
def main() :
obj = MyMath()
# Simple test
obj.hectare_to_square_km(1)
obj.hectare_to_square_km(2021)
obj.hectare_to_square_km(1500.6)
if __name__ == "__main__": main()
Output
[ 1 ] Hectare is equal to [ 0.01 ] Square Kilometer
[ 2021 ] Hectare is equal to [ 20.21 ] Square Kilometer
[ 1500.6 ] Hectare is equal to [ 15.005999999999998 ] Square Kilometer
# Ruby program
# Convert hectare to square kilometer
class MyMath
# Find the square kilometer of given hectare
def hectare_to_square_km(hectare)
# Calculate square kilometer by using hectare
# Formula : (hectare / 100)
square_km = (hectare / 100)
print("[", hectare ,"] Hectare is equal to [", square_km ,"] Square Kilometer \n")
end
end
def main()
obj = MyMath.new()
# Simple test
obj.hectare_to_square_km(1)
obj.hectare_to_square_km(2021)
obj.hectare_to_square_km(1500.6)
end
main()
Output
[1] Hectare is equal to [0] Square Kilometer
[2021] Hectare is equal to [20] Square Kilometer
[1500.6] Hectare is equal to [15.005999999999998] Square Kilometer
/*
Scala program
Convert hectare to square kilometer
*/
class MyMath
{
//Find the square kilometer of given hectare
def hectare_to_square_km(hectare: Double): Unit = {
// Calculate square kilometer by using hectare
// Formula : (hectare / 100)
var square_km: Double = (hectare / 100);
print("[" + hectare + "] Hectare is equal to [" + square_km + "] Square Kilometer \n");
}
}
object Main
{
def main(args: Array[String]): Unit = {
var obj: MyMath = new MyMath();
//Simple test
obj.hectare_to_square_km(1);
obj.hectare_to_square_km(2021);
obj.hectare_to_square_km(1500.6);
}
}
Output
[1.0] Hectare is equal to [0.01] Square Kilometer
[2021.0] Hectare is equal to [20.21] Square Kilometer
[1500.6] Hectare is equal to [15.005999999999998] Square Kilometer
/*
Swift program
Convert hectare to square kilometer
*/
class MyMath
{
//Find the square kilometer of given hectare
func hectare_to_square_km(_ hectare: Double)
{
// Calculate square kilometer by using hectare
// Formula : (hectare / 100)
let square_km: Double = (hectare / 100);
print("[", hectare ,"] Hectare is equal to [", square_km ,"] Square Kilometer \n", terminator: "");
}
}
func main()
{
let obj: MyMath = MyMath();
//Simple test
obj.hectare_to_square_km(1);
obj.hectare_to_square_km(2021);
obj.hectare_to_square_km(1500.6);
}
main();
Output
[ 1.0 ] Hectare is equal to [ 0.01 ] Square Kilometer
[ 2021.0 ] Hectare is equal to [ 20.21 ] Square Kilometer
[ 1500.6 ] Hectare is equal to [ 15.006 ] Square Kilometer
Time Complexity of the Code
The provided code has a time complexity of O(1) since the conversion formula involves basic arithmetic operations (division), which take constant time irrespective of the input size. The time complexity remains constant regardless of how large or small the input hectare value is.
Finally
This article explained how to convert hectares to square kilometers using a simple formula. We provided an overview of the problem, including an explanation and a suitable example. Furthermore, we presented the pseudocode and algorithm for the conversion. Finally, we analyzed the resultant output and discussed the time complexity of the code. Understanding this conversion is essential for various real-world applications and is a valuable tool in the fields of land measurement, agriculture, and urban planning.
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