Newton Raphson's Method To find Square Root Using C
#include< stdio.h >
#include< conio.h >
#include< math.h >
float f(float x,int n)
{
return(x*x-n);
}
float df(float x)
{
return 2*x;
}
void main()
{
float b=5,m,e=0.0001,num;
int i;
clrscr();
printf("\n Newton Raphson's Method : To find Square Root");
printf("\n Enter Number whose Square root to be found :- \n");
scanf("%f",&num);
m=(b)-((f(b,num))/df(b));
i=1;
while(fabs(f(m,num))>e)
{
b=m;
m=(b)-((f(b,num))/df(b));
i=i+1;
printf("\n Square root of %.2f is %.2f",num,m);
getch();
}
}
OUTPUT:
#include< stdio.h >
#include< conio.h >
#include< math.h >
float f(float x,int n)
{
return(x*x-n);
}
float df(float x)
{
return 2*x;
}
void main()
{
float b=5,m,e=0.0001,num;
int i;
clrscr();
printf("\n Newton Raphson's Method : To find Square Root");
printf("\n Enter Number whose Square root to be found :- \n");
scanf("%f",&num);
m=(b)-((f(b,num))/df(b));
i=1;
while(fabs(f(m,num))>e)
{
b=m;
m=(b)-((f(b,num))/df(b));
i=i+1;
printf("\n Square root of %.2f is %.2f",num,m);
getch();
}
}
OUTPUT:
No comments:
Post a Comment