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

1. Member
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. Member
Join Date
May 2008
Posts
2,302

## 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. Member
Join Date
Oct 2005
Posts
2,394

## 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. Member
Join Date
May 2008
Posts
2,393

## 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. Member
Join Date
Feb 2008
Posts
1,856

## 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. Member
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();

}

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•