program to find the square root of a given number

Please support our C advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Apr 2008
Posts: 3
Reputation: scapu is an unknown quantity at this point 
Solved Threads: 0
scapu scapu is offline Offline
Newbie Poster

program to find the square root of a given number

 
0
  #1
May 24th, 2008
Hello, Can anybody help me in this program.

Write a C program to find the square root of a given number?

I can understand only C and please i need answer in C only.

In this question i should not use function and i have to write a code for my self. Will anybody help me ...I need this for my test prepration.

Scapu
Reply With Quote Quick reply to this message  
Join Date: Dec 2005
Posts: 5,850
Reputation: Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute 
Solved Threads: 751
Team Colleague
Salem's Avatar
Salem Salem is offline Offline
Void main'ers are DOOMed

Re: program to find the square root of a given number

 
0
  #2
May 24th, 2008
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 1,669
Reputation: jephthah has much to be proud of jephthah has much to be proud of jephthah has much to be proud of jephthah has much to be proud of jephthah has much to be proud of jephthah has much to be proud of jephthah has much to be proud of jephthah has much to be proud of 
Solved Threads: 123
jephthah's Avatar
jephthah jephthah is offline Offline
Posting Virtuoso

Re: program to find the square root of a given number

 
0
  #3
May 24th, 2008
here you go:
  1. #define GIT_R_DUN 3.00
  2. #include <stdio.h>
  3. #include <math.h>
  4. int main()
  5. {
  6. double x = GIT_R_DUN;
  7. printf("root of %f = %f\n",x,sqrt(x));
  8. }

if questioned, tell your professor that NO ONE in the "real world" writes this stuff from scratch, then ask him if he's ever had a "real job". If he still complains, send him here to talk to me.


.
Last edited by jephthah; May 24th, 2008 at 2:27 pm.
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 296
Reputation: tesuji is on a distinguished road 
Solved Threads: 42
tesuji tesuji is offline Offline
Posting Whiz in Training

Re: program to find the square root of a given number

 
0
  #4
May 24th, 2008
Hi scapu,

Don't lose heart!

Pick out an algorithm, for example Newton's method seems to be rather comfortable to compute the square root of a given number. This method is also identical to the ancient method of the Babylonian to draw the square root of a given number, it s also called the divide-and-average algorithm. http://www.homeschoolmath.net/teachi...-algorithm.php discuss it. Try to design a c program. No matter whether it is complete, compiles with error, or produces imperfect results you should post your tentative steps. Then we will help you.

P.s. I don't agree with the concept of the latter post. The intention of computing the square root that way is not to do it plain "from scratch" but to learn fundamental concepts of numeric analysis, such as approximation, iteration, recurrence, numerical stability, and finally to get acquainted with famous Newton method.

krs,
tesu
Last edited by tesuji; May 24th, 2008 at 8:02 pm.
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 19
Reputation: chsarp_vijay is an unknown quantity at this point 
Solved Threads: 0
chsarp_vijay chsarp_vijay is offline Offline
Newbie Poster

Re: program to find the square root of a given number

 
-1
  #5
Jun 2nd, 2008
  1. float SquareRoot(float number)
  2. {
  3. long int inter_value = 0;
  4. float x_value = 0.0,
  5. y_value = 0.0;
  6. float f_value = 1.5F;
  7.  
  8. x_value = number * 0.5F;
  9. y_value = number;
  10. inter_value = * ( long int * ) &y_value;
  11. inter_value = 0x5f3759df - ( inter_value >> 1 );
  12. y_value = * ( float * ) &inter_value;
  13. y_value = y_value * ( f_value - ( x_value * y_value * y_value ) );
  14. y_value = y_value * ( f_value - ( x_value * y_value * y_value ) );
  15. return number * y_value;
  16. }

Just let me know if u face any problems

Regards,
Vijay Bhaskar



Originally Posted by scapu View Post
Hello, Can anybody help me in this program.

Write a C program to find the square root of a given number?

I can understand only C and please i need answer in C only.

In this question i should not use function and i have to write a code for my self. Will anybody help me ...I need this for my test prepration.

Scapu
Last edited by WolfPack; Jun 2nd, 2008 at 2:33 pm. Reason: Added [CODE=CPP][/CODE] Tags
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 1,669
Reputation: jephthah has much to be proud of jephthah has much to be proud of jephthah has much to be proud of jephthah has much to be proud of jephthah has much to be proud of jephthah has much to be proud of jephthah has much to be proud of jephthah has much to be proud of 
Solved Threads: 123
jephthah's Avatar
jephthah jephthah is offline Offline
Posting Virtuoso

Re: program to find the square root of a given number

 
0
  #6
Jun 2nd, 2008
hey, Vijay, please become familiar with the rules of the forums... you know, the ones that are posted as "ANNOUNCEMENTS" and stuck to the top of every forum here.

(1) http://www.daniweb.com/forums/announcement118-2.html

and

(2) http://www.daniweb.com/forums/announcement118-3.html


.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:




Views: 5340 | Replies: 5
Thread Tools Search this Thread



Tag cloud for C
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC