forked from sanchitahuja/CP-4th-Sem
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path17iii.cpp
More file actions
65 lines (52 loc) · 1012 Bytes
/
17iii.cpp
File metadata and controls
65 lines (52 loc) · 1012 Bytes
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
#include<stdio.h>
#include<math.h>
float func(float j)
{
return exp(j+cos(2*j));
}
int main()
{
float ul,ll,ss;
int i=0;
printf("\n Enter the Upper Limit : ");
scanf("%f",&ul);
printf("\n Enter the Lower Limit : ");
scanf("%f",&ll);
float X[13],Y[13],sum=0,addend;
X[0]=ll;
X[12]=ul;
ss=(ul-ll)/12;
Y[0]=func(X[0]);
Y[12]=func(X[12]);
//Populating X and Y
for(i=1;i<12;i++)
{
X[i]=X[i-1]+ss;
Y[i]=func(X[i]);
}
int c=0;
printf("\n");
for(i=0;i<13;i++)
{
if(c==0)
addend=7*Y[i];
else if(c==1)
addend=32*Y[i];
else if(c==2)
addend=12*Y[i];
else if(c==3)
addend=32*Y[i];
else
{
addend=7*Y[i];
c=-1;
if(i!=12)
i--;
}
c++;
sum+=addend;
}
float integ=((2*ss)/45)*sum;
printf("\nIntegration is %f",integ);
return 1;
}