Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7688599
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T19:57:31+00:00 2026-05-31T19:57:31+00:00

I wrote a simple program to solve the math problem: A^2+B^2 = 12 A*B

  • 0

I wrote a simple program to solve the math problem:

A^2+B^2 = 12
A*B = 9
(A+B)^2 = y

My program is looping through each number starting at 0.000000001, and checking to see if the first equation is true (the second one is always true because I always assign double B = 9 / A).

Then it writes the results and pauses. This is taking forever to run since its doing a lot of math, I was wondering if I made any mistakes so I can fix them? Here is my code:

namespace AnnoyingMath1
{
    class Program
    {
        static void Main(string[] args)
        {
            for (double a = 0.00000001; a < 9; a += 0.00000001) {
                double b = 9 / a;
                if (Math.Pow(a, 2) + Math.Pow(b, 2) == 12)
                {
                    if (a * b == 9) // always true because b = 9 / a
                    {
                        Console.WriteLine("SUCCESS! a = " + a.ToString() + ", b = " + b.ToString() + ", y = (a+b)^2 = " + (Math.Pow(a + b, 2)).ToString() );
                        Console.ReadLine();
                    }
                }
                else {
                    Console.WriteLine("fail1 " + a.ToString() + " , " + b.ToString());
                }
            }
        }
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T19:57:32+00:00Added an answer on May 31, 2026 at 7:57 pm

    Yes. It does.

    statements such as:

    if (a * b == 9) // always true because b = 9 / a  WRONG, because you are dealing with floating point
    

    are incorrect.

    Never directly compare floating point values. Use a delta instead:

    epsilon = 0.000001
    if (Abs(a*b - 9) <= epsilon )
    

    There are many similar questions on StackOverflow.

    Please read What Every Computer Scientist Should Know About Floating-Point Arithmetic

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The problem is this: I wrote a simple program that uses FFMPEG. compile as
I just wrote my first C# program. It's a simple piece of code which
I wrote a simple program to test a theory that finally block will always
I wrote a simple program in java web forms but i am receiving the
A while back I wrote a simple python program to brute-force the single solution
I recently wrote a program that used a simple producer/consumer pattern. It initially had
I wrote a simple test program, where I was doing Complex to Complex FT's
I wrote this simple Java program which connects to internic server and returns the
Yesterday I wrote a simple Python program (really simple as shown below) to validate
I wrote a simple Windows Forms program in C#. I want to be able

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.