| | |
program to find the square root of a given number
Please support our C advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Apr 2008
Posts: 3
Reputation:
Solved Threads: 0
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
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
here you go:
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.
.
C Syntax (Toggle Plain Text)
#define GIT_R_DUN 3.00 #include <stdio.h> #include <math.h> int main() { double x = GIT_R_DUN; printf("root of %f = %f\n",x,sqrt(x)); }
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.
•
•
Join Date: Apr 2008
Posts: 296
Reputation:
Solved Threads: 42
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
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.
•
•
Join Date: May 2008
Posts: 19
Reputation:
Solved Threads: 0
cpp Syntax (Toggle Plain Text)
float SquareRoot(float number) { long int inter_value = 0; float x_value = 0.0, y_value = 0.0; float f_value = 1.5F; x_value = number * 0.5F; y_value = number; inter_value = * ( long int * ) &y_value; inter_value = 0x5f3759df - ( inter_value >> 1 ); y_value = * ( float * ) &inter_value; y_value = y_value * ( f_value - ( x_value * y_value * y_value ) ); y_value = y_value * ( f_value - ( x_value * y_value * y_value ) ); return number * y_value; }
Just let me know if u face any problems
Regards,
Vijay Bhaskar
•
•
•
•
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
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
.
(1) http://www.daniweb.com/forums/announcement118-2.html
and
(2) http://www.daniweb.com/forums/announcement118-3.html
.
![]() |
Similar Threads
- square root guestimator!! oh the loops! (C++)
- Program that determines if a number is prime (C++)
- Is it possible to create a square root program without math.h (C++)
- help with square root finder (C++)
- Please Help!!! (Java)
- Trying To Find The Square Root Of Each Number Of A Array (C++)
- need hekp with C++ Calculator program (C++)
- I just need help starting this program please (C++)
Other Threads in the C Forum
- Previous Thread: fscanf and reading from binary file
- Next Thread: 2D Arrays Initialization
Views: 5340 | Replies: 5
| Thread Tools | Search this Thread |
Tag cloud for C
#include * append array arrays asterisks bash binarysearch calculate changingto char character cm command copyimagefile creafecopyofanytypeoffileinc createprocess() database directory dynamic execv feet fgets file floatingpointvalidation fork forloop framework function functions getlogicaldrivestrin givemetehcodez global grade graphics gtkwinlinux hacking histogram homework ide include incrementoperators input intmain() iso kernel keyboard kilometer lazy license linked linkedlist linux list lists looping loopinsideloop. lowest matrix meter microsoft mqqueue number oddnumber odf openwebfoundation overwrite pause pdf pointer posix process program programming radix recursion recv recvblocked research reversing segmentationfault sequential single socket socketprogramming spoonfeeding standard strchr string student system testing threads turboc unix urboc user variable whythiscodecausesegmentationfault windowsapi






