Posted on by Kalkicode
Code Conversion

# Convert the square yard to square meter

Unit conversion is a common task in various fields, including mathematics, engineering, and everyday life. In this article, we will focus on converting square yards to square meters using a program. We'll introduce the problem, explain the solution through examples, provide the algorithm, and analyze the time complexity of the code.

## Problem Statement

The problem is to convert a given area in square yards to the equivalent area in square meters. This involves taking a value in square yards, using the conversion factor, and obtaining the corresponding value in square meters. The formula for conversion is:

Square Meters = Square Yards / 1.196

## Example

Let's take an area of 12.7 square yards as an example. To convert this to square meters, we'll use the formula:

Square Meters = 12.7 / 1.196 ≈ 10.618729

So, 12.7 square yards is approximately equal to 10.618729 square meters.

## Idea to Solve the Problem

To solve this problem, we need to write a C program that takes an area in square yards as input, applies the conversion formula, and outputs the corresponding area in square meters.

## Pseudocode

Here's the pseudocode for the solution:

function square_yard_to_square_metre(square_yard)
square_metre = square_yard / 1.196
output "Square yard:", square_yard, "Square Metre:", square_metre
end function

main
square_yard_to_square_metre(1)
square_yard_to_square_metre(12.7)
square_yard_to_square_metre(34)
end main

## Algorithm Explanation

1. The square_yard_to_square_metre function takes a single parameter, square_yard, which represents the area in square yards to be converted.
2. Inside the function, the area in square yards is divided by the conversion factor (1.196) to calculate the equivalent area in square meters.
3. The calculated values of square yard and square meter are then printed as output, along with appropriate labels.
4. In the main function, the square_yard_to_square_metre function is called three times with different test values to demonstrate the conversion.

## Program Solution

//C Program
//Convert the square yard to square meter
#include <stdio.h>
//Find the square metre of given square yard
void square_yard_to_square_metre(double square_yard)
{
// Formula : (square_yard / 1.196)
// Calculate given square_yard to square_metre
double square_metre = (square_yard / 1.196);
//Display result
printf("Square yard : %lf  Square Metre : %lf\n", square_yard, square_metre);
}
int main()
{
//Simple test
square_yard_to_square_metre(1);
square_yard_to_square_metre(12.7);
square_yard_to_square_metre(34);
return 0;
}

#### Output

Square yard : 1.000000  Square Metre : 0.836120
Square yard : 12.700000  Square Metre : 10.618729
Square yard : 34.000000  Square Metre : 28.428094
/*
Java program
Convert the square yard to square meter
*/
class MyMath
{
//Find the square metre of given square yard
public void square_yard_to_square_metre(double square_yard)
{
// Formula : (square_yard / 1.196)
// Calculate given square_yard to square_metre
double square_metre = (square_yard / 1.196);
System.out.print("Square yard : " + square_yard + " Square Metre : " + square_metre + "\n");
}
public static void main(String[] args)
{
MyMath obj = new MyMath();
//Simple test
obj.square_yard_to_square_metre(1);
obj.square_yard_to_square_metre(12.7);
obj.square_yard_to_square_metre(34);
}
}

#### Output

Square yard : 1.0 Square Metre : 0.8361204013377926
Square yard : 12.7 Square Metre : 10.618729096989966
Square yard : 34.0 Square Metre : 28.42809364548495
/*
C++ program
Convert the square yard to square meter
*/
#include<iostream>

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

#### Output

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

#### Output

Square yard : 1 Square Metre : 0.836120401337793
Square yard : 12.7 Square Metre : 10.61872909699
Square yard : 34 Square Metre : 28.4280936454849
<?php
/*
Php program
Convert the square yard to square meter
*/
class MyMath
{
//Find the square metre of given square yard
public	function square_yard_to_square_metre(\$square_yard)
{
// Formula : (square_yard / 1.196)
// Calculate given square_yard to square_metre
\$square_metre = (\$square_yard / 1.196);
echo "Square yard : ". \$square_yard ." Square Metre : ". \$square_metre ."\n";
}
}

function main()
{
\$obj = new MyMath();
//Simple test
\$obj->square_yard_to_square_metre(1);
\$obj->square_yard_to_square_metre(12.7);
\$obj->square_yard_to_square_metre(34);
}
main();

#### Output

Square yard : 1 Square Metre : 0.83612040133779
Square yard : 12.7 Square Metre : 10.61872909699
Square yard : 34 Square Metre : 28.428093645485
/*
Node Js program
Convert the square yard to square meter
*/
class MyMath
{
//Find the square metre of given square yard
square_yard_to_square_metre(square_yard)
{
// Formula : (square_yard / 1.196)
// Calculate given square_yard to square_metre
var square_metre = (square_yard / 1.196);
process.stdout.write("Square yard : " + square_yard + " Square Metre : " + square_metre + "\n");
}
}

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

#### Output

Square yard : 1 Square Metre : 0.8361204013377926
Square yard : 12.7 Square Metre : 10.618729096989966
Square yard : 34 Square Metre : 28.42809364548495
# Python 3 program
# Convert the square yard to square meter

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

def main() :
obj = MyMath()
# Simple test
obj.square_yard_to_square_metre(1)
obj.square_yard_to_square_metre(12.7)
obj.square_yard_to_square_metre(34)

if __name__ == "__main__": main()

#### Output

Square yard :  1  Square Metre :  0.8361204013377926
Square yard :  12.7  Square Metre :  10.618729096989966
Square yard :  34  Square Metre :  28.42809364548495
# Ruby program
# Convert the square yard to square meter

class MyMath

# Find the square metre of given square yard
def square_yard_to_square_metre(square_yard)

#  Formula : (square_yard / 1.196)
#  Calculate given square_yard to square_metre
square_metre = (square_yard / 1.196)
print("Square yard : ", square_yard ," Square Metre : ", square_metre ,"\n")
end
end
def main()

obj = MyMath.new()
# Simple test
obj.square_yard_to_square_metre(1)
obj.square_yard_to_square_metre(12.7)
obj.square_yard_to_square_metre(34)
end
main()

#### Output

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

#### Output

Square yard : 1.0 Square Metre : 0.8361204013377926
Square yard : 12.7 Square Metre : 10.618729096989966
Square yard : 34.0 Square Metre : 28.42809364548495
/*
Swift program
Convert the square yard to square meter
*/
class MyMath
{
//Find the square metre of given square yard
func square_yard_to_square_metre(_ square_yard: Double)
{
// Formula : (square_yard / 1.196)
// Calculate given square_yard to square_metre
let square_metre: Double = (square_yard / 1.196);
print("Square yard : ", square_yard ," Square Metre : ", square_metre ,"\n", terminator: "");
}
}
func main()
{
let obj: MyMath = MyMath();
//Simple test
obj.square_yard_to_square_metre(1);
obj.square_yard_to_square_metre(12.7);
obj.square_yard_to_square_metre(34);
}
main();

#### Output

Square yard :  1.0  Square Metre :  0.836120401337793
Square yard :  12.7  Square Metre :  10.61872909699
Square yard :  34.0  Square Metre :  28.4280936454849

## Time Complexity

The time complexity of the conversion process is constant for each conversion, as it only involves simple arithmetic operations (division). Therefore, the time complexity of the code is O(1), implying that the execution time remains constant regardless of the input size.

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