Free html code for fraction adding calculator -fraction adding calculator html code

We will try to give you a new code for every day . 

You can create your tool website and earn unlimited with google and google adsense. 
You can create your free website with the google product name as Blogger. 
You just open Blogger.com 
create your account and write or paste this code in the html view of your blogger. 

so the Code is given below you can copy and paste in your website . 

Here is a code for Adding Fraction calculator convertor HTML code    





 <html lang="en">

<head>

    <meta charset="UTF-8"></meta>

    <meta content="width=device-width, initial-scale=1.0" name="viewport"></meta>

    <title>Fraction Adding Calculator</title>

    <style>

        body {

            font-family: Arial, sans-serif;

            text-align: center;

            margin: 50px;

        }

    </style>

</head>

<body>

    <h2>Fraction Adding Calculator</h2>

    <label for="fractionInput">Enter Fractions (e.g., 1/2, 3/4, 1/3):</label>

    <input id="fractionInput" placeholder="Enter fractions" type="text" />

    <button onclick="addFractions()">Add Fractions</button>


    <p id="result"></p>


    <script>

        function addFractions() {

            // Get the fraction input value

            var fractionInput = document.getElementById("fractionInput").value;


            // Split the input into individual fractions

            var fractions = fractionInput.split(',');


            // Initialize variables to store the sum

            var sumNumerator = 0;

            var sumDenominator = 1; // Initialize to 1 to represent the identity element for addition


            // Iterate through each fraction

            for (var i = 0; i < fractions.length; i++) {

                // Extract numerator and denominator from the current fraction

                var parts = fractions[i].split('/');

                var numerator = parseInt(parts[0]);

                var denominator = parseInt(parts[1]);


                // Check if the denominator is not zero

                if (denominator === 0) {

                    document.getElementById("result").innerHTML = "Denominator cannot be zero.";

                    return;

                }


                // Find a common denominator

                var commonDenominator = findCommonDenominator(sumDenominator, denominator);


                // Calculate the sum

                sumNumerator = sumNumerator * (commonDenominator / sumDenominator) +

                               numerator * (commonDenominator / denominator);

                sumDenominator = commonDenominator;

            }


            // Simplify the result

            var gcd = findGCD(sumNumerator, sumDenominator);

            var simplifiedNumerator = sumNumerator / gcd;

            var simplifiedDenominator = sumDenominator / gcd;


            // Display the result

            document.getElementById("result").innerHTML = "Sum: " + simplifiedNumerator + "/" + simplifiedDenominator;

        }


        function findCommonDenominator(a, b) {

            // Find the least common multiple (LCM) as the common denominator

            return (a * b) / findGCD(a, b);

        }


        function findGCD(a, b) {

            // Find the Greatest Common Divisor (GCD) using Euclidean algorithm

            return b === 0 ? a : findGCD(b, a % b);

        }

    </script>

</body>

Comments

Popular posts from this blog

बस माल पैक करो और कंपनी को वापस कर दो और 60 हजार रुपए महीना कमाओ, bindi packing business

घर बैठे करे पैकिंग का काम कमाए लाखो रूपये महीना , पॉपकॉर्न कंपनी दे रही है मौका

3 ONLINE EARNING APP , NO CONDITION , NO INVESTMENT , ONLY EARNING , घर बैठे पैसा कमाने के लिए 3 सबसे बढ़िया APP .