C examples for Function:Function Definition
Create a function to calculate the Square Root of a Number
#include <stdio.h> float absoluteValue (float x){ if (x < 0) x = -x;// w ww .ja v a2 s.c o m return x; } float squareRoot (float x){ const float epsilon = .00001; float guess = 1.0; while (absoluteValue (guess * guess - x) >= epsilon) guess = (x / guess + guess) / 2.0; return guess; } int main (void){ printf ("squareRoot (2.0) = %f\n", squareRoot (2.0)); return 0; }