Function for square root without using sqrt() function

Started by thiruvasagamani, Sep 22, 2008, 05:33 PM

previous topic - next topic
Go Down


Write a function for square root without using sqrt() function

Code: [Select]
#include <stdio.h>
#include <conio.h>

float sqroot( float x)
float a , b;
a = x; // copy given value to 'a'
b = a; // copy value of 'a' to 'b' before 'a' is modify
a = (a + x/a) / 2; // modify 'a' value until we reach sqroot result
while( a!= b); // execute loop until a == b
return( a); // 'a ' or 'b' is sqroot of 'x'

float x;
float sqroot( float);
printf( enter any number \n");
scanf("%f", &x);
if( x > 0)
printf(" SQRT(%f) = %f\n", sqroot( x)); // display sqrt(49) = 7
if(x < 0)
printf(" SQRT(%f) = %fi \n", sqroot( -x)); // display sqrt( -49) = 7i
printf(" square root is 0 \n");


If you enter 'x' values as 49 output is 7
If 'x' value is -25 output is 5i
If 'x' value is 256 output is 16
Thiruvasakamani Karnan

Ashok G

Thanks it is just easy and simple to be integrated with any language

Go Up

Quick Reply

With Quick-Reply you can write a post when viewing a topic without loading a new page. You can still use bulletin board code and smileys as you would in a normal post.

Warning: this topic has not been posted in for at least 120 days.
Unless you're sure you want to reply, please consider starting a new topic.

Note: this post will not display until it's been approved by a moderator.
Please leave this box empty:

Type the letters shown in the picture
Listen to the letters / Request another image

Type the letters shown in the picture:

shortcuts: alt+s submit/post or alt+p preview
IT Acumens Web Designing Chennai | GinGly :: Build your Personal Website | CineBuzz :: Cinema News | My Kids Diary :: Kids Memories Writing :: Book Website @ 349 Rs monthly
Copyright 2005 - 2020 :: IT Acumens :: All Rights Reserved. :: Sitemap
ITAcumens Discussion Forum with 2 lakhs post running for 15 years - Powered by IT Acumens Dedicated Server