ccplusplus.com
Learn C, C++ Concepts
Monday, September 12, 2011
square root of number in c
/****************************************************** * File : square-root-of-number.c * Author : Saurabh Gupta * Desc : calculate square root example c code * * Source : http://saurabhgupta0527.blogspot.com/ * Created : AM 09:54 12 September 2011 * Note : *****************************************************/ #include
int main() { float fSquareRoot, fTempSquareRoot1, e = 0.00001, fTempSquareRoot2, fInputNumber; printf("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n"); printf("XXX PROGRAM TO FIND SQUARE ROOT XXX\n"); printf("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n"); printf("ENTER A NUMBER :"); scanf("%f", &fInputNumber); fSquareRoot = fInputNumber; fTempSquareRoot2 = fSquareRoot * fSquareRoot; while (fTempSquareRoot2 - fInputNumber >= e) { fTempSquareRoot1 = (fSquareRoot + (fInputNumber / fSquareRoot)) / 2; fSquareRoot = fTempSquareRoot1; fTempSquareRoot2 = fSquareRoot * fSquareRoot; } printf("SQUARE ROOT IS = %f\n", fSquareRoot); printf("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\n"); return 0; } /* * * [sgupta@rhel54x64 c]$ gcc square-root-of-number.c -o square-root-of-number [sgupta@rhel54x64 c]$ ./square-root-of-number XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX XXX PROGRAM TO FIND SQUARE ROOT XXX XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX ENTER A NUMBER :12 SQUARE ROOT IS = 3.464102 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX [sgupta@rhel54x64 c]$ */
No comments:
Post a Comment
Newer Post
Older Post
Home
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment