Results 1 to 6 of 6

Thread: How can I find square root using c program?

  1. #1
    Join Date
    Dec 2009
    Posts
    68

    How can I find square root using c program?

    Hi Friends,

    I am coding on C program and in which I have to fin the square root of the given number. I have tried the "sqrt" function to calculate square root. But I run my program I get lots of error for this. I am getting frustrated because of this.

    Is anyone posses C program to calculate the square root of specified number? Your help would be greatly appreciable.

  2. #2
    Join Date
    May 2008
    Posts
    2,297

    Re: How can I find square root using c program?

    Refer the below c program for sqrt root . Run this program on you system and let me know if it is executed successfully or not.
    #include <stdio.h>
    #include <math.h>

    int main(void)
    {
    double p = 25.0, rt;

    rt = sqrt(p);

    printf("Square root of is %f", rt);

    return 0;
    }

  3. #3
    Join Date
    Oct 2005
    Posts
    2,393

    Re: How can I find square root using c program?

    Hi,

    Try with following function code, use the this logic to calculate the square root using the c language. I hope it will definitely work for you.
    double squroot( const double fg)
    {

    double n = fg / 2.0;
    double lstX = 0.0;

    while(n != lstX)

    {

    lstX = n;
    n = (n + fg/n) / 2.0;

    }

  4. #4
    Join Date
    May 2008
    Posts
    2,389

    Re: How can I find square root using c program?

    Square root program:
    main()
    {

    float p,q,f=0.00001,a,l;

    clrscr();

    printf(" Square root program");

    p=l;a=p*p;

    while(a-l>=f)

    {

    q=(p+(l/p))/2;

    p=q;

    q=p*p;

    }
    printf("square root = %f",p);
    getch();

    }

    while(l!=-1);

    getch();
    }

  5. #5
    Join Date
    Feb 2008
    Posts
    1,852

    Re: How can I find square root using c program?

    Hello Friend,

    The program to calculate the square root is very complicated than calculating the square of any given number. You should use "while" loop to check conditions for this program. It will be more complicated for you if you use the "for loop". see below:
    while(nm != 0)// here nm is the which is calculated by division of two
    {
    // body of loop
    }

  6. #6
    Join Date
    Jan 2008
    Posts
    1,521

    Re: How can I find square root using c program?

    Hi,

    Have you tried below code to calculate square root using c program? Please try this:
    #include <math.h>
    #include <stdio.h>

    Void main()
    {

    float q = 64.0, w;

    w = sqrt(q);

    printf("Square root of given number =%f", w);

    getch();

    }

Similar Threads

  1. Square Root Symbol In Java
    By Sheenas in forum Software Development
    Replies: 5
    Last Post: 27-01-2010, 10:27 AM
  2. Square root and Visual C++ compiler
    By Luis234 in forum Software Development
    Replies: 4
    Last Post: 25-04-2009, 12:02 AM
  3. Can not find root
    By HELOISE in forum Motherboard Processor & RAM
    Replies: 2
    Last Post: 28-03-2009, 01:27 PM
  4. Program to calulate the square of number
    By windows_user in forum Software Development
    Replies: 3
    Last Post: 10-12-2008, 04:41 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,711,723,784.03132 seconds with 17 queries