Posted on by Kalkicode
Code Conversion

# Convert the square foot to square yard

Converting measurements from one unit to another is a common task in various fields, from construction to real estate. When dealing with areas, it's often necessary to convert between different area units, such as square feet and square yards. Square feet and square yards are both units of area, and converting between them allows us to express the same space in different terms.

## Problem Statement

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

## Example

Let's consider the first test case from your code:

• Area in square feet: 1

We want to convert this area to square yards.

## Idea to Solve the Problem

The conversion from square feet to square yards involves dividing the given area in square feet by a conversion factor. The conversion factor between square feet and square yards is 1/9, since 1 square yard equals 9 square feet.

## Pseudocode

``````square_foot_to_square_yard(square_foot):
square_yard = square_foot / 9
display square_foot, square_yard``````

## Algorithm Explanation

1. The `square_foot_to_square_yard` function takes an area in square feet as input.
2. It divides the input value by the conversion factor 9 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 feet.

## Program Solution

``````/*
Java program
Convert the square foot to square yard
*/
class MyMath
{
//Find the square foot of given square yard
public void square_foot_to_square_yard(double square_foot)
{
// Calculate square yard
// Formula : (Square Foot / 9)
double square_yard = (square_foot / 9);
System.out.print("Square Foot : " + square_foot + " Square Yard : " + square_yard + "\n");
}
public static void main(String[] args)
{
MyMath obj = new MyMath();
//Simple test
obj.square_foot_to_square_yard(1);
obj.square_foot_to_square_yard(14);
obj.square_foot_to_square_yard(50.7);
}
}``````

#### Output

``````Square Foot : 1.0 Square Yard : 0.1111111111111111
Square Foot : 14.0 Square Yard : 1.5555555555555556
Square Foot : 50.7 Square Yard : 5.633333333333334``````
``````/*
C++ program
Convert the square foot to square yard
*/
#include<iostream>

using namespace std;
class MyMath
{
public:
//Find the square foot of given square yard
void square_foot_to_square_yard(double square_foot)
{
// Calculate square yard
// Formula : (Square Foot / 9)
double square_yard = (square_foot / 9);
cout << "Square Foot : " << square_foot << " Square Yard : " << square_yard << "\n";
}
};
int main()
{
MyMath obj ;
//Simple test
obj.square_foot_to_square_yard(1);
obj.square_foot_to_square_yard(14);
obj.square_foot_to_square_yard(50.7);
return 0;
}``````

#### Output

``````Square Foot : 1 Square Yard : 0.111111
Square Foot : 14 Square Yard : 1.55556
Square Foot : 50.7 Square Yard : 5.63333``````
``````/*
C# program
Convert the square foot to square yard
*/
using System;
class MyMath
{
//Find the square foot of given square yard
public void square_foot_to_square_yard(double square_foot)
{
// Calculate square yard
// Formula : (Square Foot / 9)
double square_yard = (square_foot / 9);
Console.Write("Square Foot : " + square_foot + " Square Yard : " + square_yard + "\n");
}
public static void Main(String[] args)
{
MyMath obj = new MyMath();
//Simple test
obj.square_foot_to_square_yard(1);
obj.square_foot_to_square_yard(14);
obj.square_foot_to_square_yard(50.7);
}
}``````

#### Output

``````Square Foot : 1 Square Yard : 0.111111111111111
Square Foot : 14 Square Yard : 1.55555555555556
Square Foot : 50.7 Square Yard : 5.63333333333333``````
``````<?php
/*
Php program
Convert the square foot to square yard
*/
class MyMath
{
//Find the square foot of given square yard
public	function square_foot_to_square_yard(\$square_foot)
{
// Calculate square yard
// Formula : (Square Foot / 9)
\$square_yard = (\$square_foot / 9);
echo "Square Foot : ". \$square_foot ." Square Yard : ". \$square_yard ."\n";
}
}

function main()
{
\$obj = new MyMath();
//Simple test
\$obj->square_foot_to_square_yard(1);
\$obj->square_foot_to_square_yard(14);
\$obj->square_foot_to_square_yard(50.7);
}
main();``````

#### Output

``````Square Foot : 1 Square Yard : 0.11111111111111
Square Foot : 14 Square Yard : 1.5555555555556
Square Foot : 50.7 Square Yard : 5.6333333333333``````
``````/*
Node Js program
Convert the square foot to square yard
*/
class MyMath
{
//Find the square foot of given square yard
square_foot_to_square_yard(square_foot)
{
// Calculate square yard
// Formula : (Square Foot / 9)
var square_yard = (square_foot / 9);
process.stdout.write("Square Foot : " + square_foot + " Square Yard : " + square_yard + "\n");
}
}

function main()
{
var obj = new MyMath();
//Simple test
obj.square_foot_to_square_yard(1);
obj.square_foot_to_square_yard(14);
obj.square_foot_to_square_yard(50.7);
}
main();``````

#### Output

``````Square Foot : 1 Square Yard : 0.1111111111111111
Square Foot : 14 Square Yard : 1.5555555555555556
Square Foot : 50.7 Square Yard : 5.633333333333334``````
``````# Python 3 program
# Convert the square foot to square yard

class MyMath :
# Find the square foot of given square yard
def square_foot_to_square_yard(self, square_foot) :
#  Calculate square yard
#  Formula : (Square Foot / 9)
square_yard = (square_foot / 9)
print("Square Foot : ", square_foot ," Square Yard : ", square_yard ,"\n", end = "")

def main() :
obj = MyMath()
# Simple test
obj.square_foot_to_square_yard(1)
obj.square_foot_to_square_yard(14)
obj.square_foot_to_square_yard(50.7)

if __name__ == "__main__": main()``````

#### Output

``````Square Foot :  1  Square Yard :  0.1111111111111111
Square Foot :  14  Square Yard :  1.5555555555555556
Square Foot :  50.7  Square Yard :  5.633333333333334``````
``````# Ruby program
# Convert the square foot to square yard

class MyMath

# Find the square foot of given square yard
def square_foot_to_square_yard(square_foot)

#  Calculate square yard
#  Formula : (Square Foot / 9)
square_yard = (square_foot / 9)
print("Square Foot : ", square_foot ," Square Yard : ", square_yard ,"\n")
end
end
def main()

obj = MyMath.new()
# Simple test
obj.square_foot_to_square_yard(1)
obj.square_foot_to_square_yard(14)
obj.square_foot_to_square_yard(50.7)
end
main()``````

#### Output

``````Square Foot : 1 Square Yard : 0
Square Foot : 14 Square Yard : 1
Square Foot : 50.7 Square Yard : 5.633333333333334
``````
``````/*
Scala program
Convert the square foot to square yard
*/
class MyMath
{
//Find the square foot of given square yard
def square_foot_to_square_yard(square_foot: Double): Unit = {
// Calculate square yard
// Formula : (Square Foot / 9)
var square_yard: Double = (square_foot / 9);
print("Square Foot : " + square_foot + " Square Yard : " + square_yard + "\n");
}
}
object Main
{
def main(args: Array[String]): Unit = {
var obj: MyMath = new MyMath();
//Simple test
obj.square_foot_to_square_yard(1);
obj.square_foot_to_square_yard(14);
obj.square_foot_to_square_yard(50.7);
}
}``````

#### Output

``````Square Foot : 1.0 Square Yard : 0.1111111111111111
Square Foot : 14.0 Square Yard : 1.5555555555555556
Square Foot : 50.7 Square Yard : 5.633333333333334``````
``````/*
Swift program
Convert the square foot to square yard
*/
class MyMath
{
//Find the square foot of given square yard
func square_foot_to_square_yard(_ square_foot: Double)
{
// Calculate square yard
// Formula : (Square Foot / 9)
let square_yard: Double = (square_foot / 9);
print("Square Foot : ", square_foot ," Square Yard : ", square_yard ,"\n", terminator: "");
}
}
func main()
{
let obj: MyMath = MyMath();
//Simple test
obj.square_foot_to_square_yard(1);
obj.square_foot_to_square_yard(14);
obj.square_foot_to_square_yard(50.7);
}
main();``````

#### Output

``````Square Foot :  1.0  Square Yard :  0.111111111111111
Square Foot :  14.0  Square Yard :  1.55555555555556
Square Foot :  50.7  Square Yard :  5.63333333333333``````

## Resultant Output Explanation

For the first test case (1 square foot):

• Area in square feet: 1.0
• Equivalent area in square yards: 0.111...

For the second test case (14 square feet):

• Area in square feet: 14.0
• Equivalent area in square yards: 1.555...

For the third test case (50.7 square feet):

• Area in square feet: 50.7
• Equivalent area in square yards: 5.633...

## 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 feet.

## 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.

Categories
Relative Post