[ create a new paste ] login | about

Link: http://codepad.org/cId9Wc1M    [ raw code | output | fork ]

swapnilghorpade - C, pasted on Nov 25:
/* Newton's Method for Sqaure root*/
#include <stdio.h>
int main()
{
	double n,i,t;
	printf("Enter no to find out square root \nusing newton's method\n");
	scanf("%lf",&n);
	
	i=(n>4)?(n/2):n;

	while(!((i*i)==n))
	{
		t=(i*i)-n;
		t=t/(i*2);

		i=i-t;
	}

	printf("\n  Square root is %.2lf",i);

return 0;
}


Output:
1
2
3
4
Enter no to find out square root 
using newton's method

  Square root is 0.00


Create a new paste based on this one


Comments: