Skip to content

Commit 394a754

Browse files
Numerical Method Lab 1 File Uploaded
1 parent 6687a6c commit 394a754

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#include <stdio.h>
2+
#include <math.h>
3+
4+
#define f(x)(x*x-7*x+10)
5+
#define e 0.0001
6+
7+
int main(){
8+
float x1, x2, x0, f1, f2, f0;
9+
10+
do{
11+
printf("Enter any two variables:");
12+
scanf("%f%f", &x1, &x2);
13+
f1=f(x1);
14+
f2=f(x2);
15+
}
16+
while(f1 * f2 > 0);
17+
18+
do{
19+
x0 = (x1+x2)/2;
20+
f0=f(x0);
21+
if(f0 == 0){
22+
break;
23+
}
24+
25+
if(f1*f0 < 0){
26+
x2 = x0;
27+
f2 = f0;
28+
}
29+
else{
30+
x1 = x0;
31+
f1 = f0;
32+
}
33+
}
34+
35+
while((fabs(x2-x1))>=e);
36+
printf("Required Root is: %f", x0);
37+
38+
return 0;
39+
}

0 commit comments

Comments
 (0)