square root of a number in C

This is a discussion on square root of a number in C within the C Programming forums, part of the General Programming Boards category; how do you find the square root of a number in C without using the predefine function sqrt() please help ...

  1. #1
    Unregistered
    Guest

    Question square root of a number in C

    how do you find the square root of a number in C without using the predefine function sqrt()


    please help if you can
    mail me at
    flashgordon@indiatimes.com

  2. #2
    zen
    zen is offline
    of Zen Hall zen's Avatar
    Join Date
    Aug 2001
    Posts
    1,007
    This might help.
    zen

  3. #3
    Registered User bljonk's Avatar
    Join Date
    Oct 2001
    Posts
    70

    Lightbulb better use it!!!

    would be better to use the predefined if you saw the source code abouve in the link; that is a lot of work.

  4. #4
    zen
    zen is offline
    of Zen Hall zen's Avatar
    Join Date
    Aug 2001
    Posts
    1,007
    It's not that much work. Alot of the code if the link was for handling user input, the function that computes the square root was just -

    Code:
    void NewtonRaphson (float accuracy, int userIn, float *answer) 
    { 
        /* Local defs * 
        float guess = 1.0; 
        float div2 = (float)userIn/2;   
    
    
        while (1)
        { 
        guess = (div2+ userIn/div2)/2;
    
        if((fabs (guess-div2) < accuracy))break;
     
        div2 = guess;
        }
    
        *answer = guess; 
    
    }
    zen

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Issue w/ Guess My Number Program
    By mkylman in forum C++ Programming
    Replies: 5
    Last Post: 08-23-2007, 01:31 AM
  2. Finding the square root! Not Working!
    By Lah in forum C Programming
    Replies: 5
    Last Post: 09-14-2003, 07:28 PM
  3. Templated Binary Tree... dear god...
    By Nakeerb in forum C++ Programming
    Replies: 15
    Last Post: 01-17-2003, 01:24 AM
  4. Homework help
    By Jigsaw in forum C++ Programming
    Replies: 2
    Last Post: 03-06-2002, 04:56 PM
  5. square root
    By help in forum C Programming
    Replies: 5
    Last Post: 08-29-2001, 05:46 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21