Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Register Tags Active Topics RSS Search Mark Forums Read

Sponsored Links



How can I find square root using c program?

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 06-01-2010
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.

Reply With Quote
  #2  
Old 06-01-2010
Member
 
Join Date: May 2008
Posts: 2,290
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.
Quote:
#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;
}
Reply With Quote
  #3  
Old 06-01-2010
Member
 
Join Date: Oct 2005
Posts: 2,389
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.
Quote:
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;

}
Reply With Quote
  #4  
Old 06-01-2010
Member
 
Join Date: May 2008
Posts: 2,382
Re: How can I find square root using c program?

Square root program:
Quote:
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();
}
Reply With Quote
  #5  
Old 06-01-2010
Member
 
Join Date: Feb 2008
Posts: 1,845
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:
Quote:
while(nm != 0)// here nm is the which is calculated by division of two
{
// body of loop
}
Reply With Quote
  #6  
Old 06-01-2010
Member
 
Join Date: Jan 2008
Posts: 1,515
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:
Quote:
#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();

}
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "How can I find square root using c program?"
Thread Thread Starter Forum Replies Last Post
Square Root Symbol In Java Sheenas Software Development 5 27-01-2010 09:27 AM
Square root and Visual C++ compiler Luis234 Software Development 4 25-04-2009 12:02 AM
Can not find root HELOISE Motherboard Processor & RAM 2 28-03-2009 01:27 PM
Program to calulate the square of number windows_user Software Development 3 10-12-2008 03:41 PM


All times are GMT +5.5. The time now is 10:09 AM.