You are here:

C/C program

Advertisement


Question
sir i would like to know how to write a C program to find the square root of a given no with out using the standardlibrary(ie math.h)

hope u answer to my question


thanxxxxxxxxxxxxxx

Answer
here is the code what i have developed just trace it and find out the logic !

/* Program to find the square root of a given number */
#include<conio.h>
#include<stdio.h>


double abs(double n)
{
  if( n >= 0 )
     return n;
  else
     return -n;
}

double sqrt(double n)
{
  double num = n / 2;
  const double range = 1.0e-7;

  do

     num = (num + n / num) / 2;
  while( abs(num * num - n) > range);

  return num;
}

void main()
{       clrscr();

  printf("%f" , sqrt(25.0));

  getch();
}

Regards !
Prince M. Premnath

Happy Programming!

C

All Answers


Answers by Expert:


Ask Experts

Volunteer


Prince M. Premnath

Expertise


I'm sure that I can solve any doubts in Turbo C ,Graphics Programing ,Mouse, Hardware Programming ,File System ,Interrupts, BIOS handling , TSR Programming , General Concepts in C Language, handling inline Assembly statements

Experience

Research over 6+ Years

Organizations
CG-VAK Softwares and Exports Limited

Education/Credentials
Masters in Computer Applications

©2012 About.com, a part of The New York Times Company. All rights reserved.