The post c program to find the square root of a number without using sqrt() appeared first on Get Program Code.

]]>#include<stdio.h> void main() { float m,n; float num; n=0.0001; // This is taken small so that we can calculate upto decimal places also printf("ENTER A NUMBER : "); scanf("%f",&num); for(m=0;m<num;m=m+n) { if((m*m)>num) { m=m-n; // This if() is used to calculate the final value as soon as the square of the number exceeds break; // the number then we deduct the value exceeded and stop the procedure using break; this is our final value which is stored in m; } } printf("%.2f",m); getch(); return 1; }

#include<stdio.h> #include<conio.h> double sqr(double , double); void main() { double i,j,n; printf("enter a number\n"); scanf("%lf",&n); j=n*100; for(i=1;i<=n*5;i++) { j=sqr(j,n); } printf("\nresult is %lf",j); getch(); } double sqr(double j, double n) { return (j+(n/j))/2; // Check out newtons Algorithm for }

Using function pow instead of sqrt()

#include<stdio.h> #include<conio.h> double squareroot(double n) { return pow(n,.5); } int main() { double n,result; printf("enter a number\n"); scanf("%lf",&n); result=squareroot(n); printf("%lf",result); return 1; }

See the Comments…

The post c program to find the square root of a number without using sqrt() appeared first on Get Program Code.

]]>