-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtext.c
59 lines (56 loc) · 1.29 KB
/
text.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include <stdio.h>
#include <conio.h>
#define g(x) sqrt(x+6)
#include <math.h>
void main()
{
float x,err;
scanf("%f",&x);
float x1;int i=0;
do
{
x1=g(x);
i++;
err=fabs(x1-x);
printf("%d approx is %f\n",i,x1);
x=x1;
}while(err>0.0005);
printf("final roots are %f\n",x);
getch();
}
/*#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#define gd(a0) (0.5/sqrt(a0+6))
#define f(x) (x*x-x-6)
#define MAX_COUNT 5000
int main()
{
int count=0;
float x0=0,x1=0,error=0;
char iffound=0;
printf("Please enter the initial value: ");
scanf("%f",&x0);
do{
x1=g(x0);
error=fabs(x1-x0);
if(count==0)
{
if(gd(x0)>1){
printf("\nThe equation is not convergent");
iffound=1;
break;
}
else{
printf("\n i xi f(xi) error");
printf("\n-------------------------------------------");
}
}
printf("\n %3d %3.5f %3.5f %3.5f",count,x0,f(x0),count==0?0:error);
x0=x1;
count++;
}while(error>0.0005 && count<MAX_COUNT);
if(!iffound)
printf("\nThe required root is: %f\n",x0);
return 0;
}*/