473,326 Members | 2,125 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Using Babylonian algorithm to find square root

my program is trying to use the babylonian algorithm in order to find the square root... i have a number for the number to have the square root taken of and also a number to run the loop... Whenever i go to print out the answer its rounding instead of giving me the answer i need... any help??

Expand|Select|Wrap|Line Numbers
  1.   double num1, num2, the_root;
  2.  
  3.  
  4.    cout<< "Enter number to have square root taken of it\n";
  5.    cin>> num1;
  6.    cout<< "Enter number for how many times to run Babylonian Algorithm\n";
  7.    cin>> num2;
  8.  
  9.    the_root= sqrt(num1);
  10.  
  11.    double the_root2 = num1/2;
  12.  
  13.    for (double count = 1; count <= num2; count++);
  14.     {
  15.       the_root2=(the_root2+num1/the_root2)/2;
  16.     ;}   
  17.  
  18.    cout.setf(ios::fixed);
  19.    cout.setf(ios::showpoint);
  20.    cout.precision(10);  
  21.    cout<< "The root of " <<num1<<" is: "<< the_root<<".\n";
  22.    cout<< "The root from the Babylonian Algorithm is: "<<the_root2<<".\n";
  23.  
  24.  
Sep 26 '07 #1
10 13600
arunmib
104 100+
for (double count = 1; count <= num2; count++);
Just TAKE A LOOK at this line again.....
Sep 26 '07 #2
sicarie
4,677 Expert Mod 4TB
socondc22-

Please have a look at your Private Messages (PM's) accessible through the link in the top right corner of the page.

Thanks
Sep 26 '07 #3
Just TAKE A LOOK at this line again.....

I still don't know what is wrong...
Sep 27 '07 #4
sicarie
4,677 Expert Mod 4TB
Well, what have you tried doing on that line to fix it?
Sep 27 '07 #5
Well, what have you tried doing on that line to fix it?
i really don't know what is wrong with the line... like i thought it was right... i prolly need to change something but i just dont know what....
Sep 27 '07 #6
can someone please help me to figure out why this part of my code is wrong...

for (double count = 1; count <= num2; count++);
Sep 28 '07 #7
im trying to figure out why its stopping at the first time through the loop of my babylonian algorithm...
Sep 28 '07 #8
Ganon11
3,652 Expert 2GB
What is num2's value??
Sep 28 '07 #9
sicarie
4,677 Expert Mod 4TB
socondc22-

Please confine your questions on the same topic to a single thread.
Sep 28 '07 #10
JosAH
11,448 Expert 8TB
can someone please help me to figure out why this part of my code is wrong...

for (double count = 1; count <= num2; count++);
hint: It's got a sad looking winking smiley at the end ... (rotated 180 degrees)

kind regards,

Jos (<--- ps. pssst: semi-colon alert! semi-colon alert! ;-)
Sep 28 '07 #11

Sign in to post your reply or Sign up for a free account.

Similar topics

32
by: Cmorriskuerten | last post by:
HI, is this is this solution to test if a number is a prime number or not: /* * Is n a prime number? * Return TRUE (1): n is a prime number * Return FALSE (0): n is a *not* a prime number...
32
by: someone else | last post by:
hi all I'm a newbie to this group. my apologies if I break any rules. I've wrote a simple program to find the first 1,000,000 primes, and to find all primes within any range (up to 200 *...
11
by: Jay | last post by:
Hey Guys, I need an algorithm/formula to do the following: I have two 32-bit timers cascaded to form a 64-bit timer, max value per timer(50sec). This is the way they work: value | timer1 |...
2
by: Clint Olsen | last post by:
Hello: I posted a thread on comp.programming awhile back asking about an algorithm I implemented on square root. The idea was to use the square root of a prime number as a convenient way to get...
1
by: Nicole | last post by:
Hi I was trying to find an algorithm to count the number of leaf nodes in a binary tree. I tried and could not find a nice way to do that. Can someone give me a clue of that ? Thanks in...
32
by: priyam.trivedi | last post by:
Hi! Could anyone tell me how to find the square root of a number without using the sqrt function. I did it by using Newton's Formula. How can it be done by using the Binomial Theorem/Taylor...
13
by: hornedw | last post by:
I have been working on a ecommerce website for myself. What I needed some assistance on was when i was trying to display the categories/subcategories for the different products. I decided to use...
3
by: victorporton | last post by:
D.K. is traveling from City A to City B. He can stop at some designated spots only. I am trying to use Dijkstra’s algorithm to determine the “spot-to-spot” path that will get D.K. from City A to...
5
by: Brosert | last post by:
I am writing (or trying to) a small program to draw a maze, that can then be traversed by a user. I have set up a grid of squares that can be either present (blocking the path) or not (allowing the...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shćllîpôpď 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.