include iostream include math using namespace std define 100 int float

 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
#include <iostream>
#include <math.h>
using namespace std;
#define n 100
int i;
float a, b, h, x, I, I1, I2, f[n];
int main()
{
cout<<"a men b ga man beriniz:\n";
cout<<"\na = ";
cin>>a;
cout<<"\nb = ";
cin>>b;
h=(b-a)/n;
f[1]=a;
f[100]=b;
for(i=1; i<n-1; i+=1)
{
x=(a+i*h);
if (i%2==0)
{
f[i]=x;
I1+=f[i];
}
else
{
f[i]=x;
I2+=f[i];
}
}
I=(h/3)*(f[1]+f[100]+(2*I1)+(4*I2));
cout<<"\nSimpson adisi boiinwa I : ="<<I;
return 0;
}