-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNBI_method.cpp
More file actions
78 lines (77 loc) · 1.16 KB
/
NBI_method.cpp
File metadata and controls
78 lines (77 loc) · 1.16 KB
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include<conio.h>
#include<stdio.h>
#include<stdlib.h>
class NBI
{
private:
int size;
float *a,x0,h,p;
void scan()
{
int i;
printf("\nenter number of inputs...");
scanf("%d",&size);
a=(float *)calloc(sizeof(float),size);
printf("\nenter starting value & difference...");
scanf("%f %f",&x0,&h);
for(i=0;i<size;i++)
{
printf("\nenter value of f(%.1f)",x0+i*h);
scanf("%f",&a[i]);
}
}
void table()
{
int i,j;
for(i=1;i<size;i++)
{
for(j=0;j<size-i;j++)
{
a[j]=a[j+1]-a[j];
}
}
printf("\ntable of y..");
for(i=0;i<size;i++)
{
printf("\n%f",a[i]);
}
}
float method()
{
int i,j;
float y=0,f,g;
for(i=size-1;i>=0;i--)
{
//printf("\np=%f y=%f",p,y);
f=1;
g=1;
for(j=1;j<=size-i-1;j++)
{
g=g*(p+j-1);
f=f*j;
}
y=y+(g*a[i]/f);
}
return y;
}
public:
float nbi(float v)
{
p=(v-(x0+(size-1)*h))/h;
return method();
}
NBI()
{
scan();
table();
}
};
int main()
{
NBI a;
float x;
printf("\nenter value of x..");
scanf("%f",&x);
printf("\nf(%.2f) = %f",x,a.nbi(x));
return 0;
}