-
Notifications
You must be signed in to change notification settings - Fork 0
/
ANTEGRAL.CPP
76 lines (70 loc) · 1003 Bytes
/
ANTEGRAL.CPP
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
#include<iostream.h>
#include<conio.h>
float Sin(float x)
{
int sign=1;
float sum=0,p,f;
for (int i=1;i<=13;i++)
{
f=p=1;
for ( int j=1;j<=(2*i-1);j++)
{
p*=x;
f*=j;
}
sum+=(p/f)*sign;
sign=-sign;
}
return sum;
}
float Cos(float x)
{
int sign=1;
float sum=0,p,f;
for (int i=1;i<=13;i++)
{
f=p=1;
for (int j=1;j<=2*i-2;j++)
{
p*=x;
f*=j;
}
sum+=p/f*sign;
sign=-sign;
}
return sum;
}
void main()
{
int a,b,i,n;
float avg,sum=0;
char ch;
clrscr();
cout<<"Enter 'c' for cos(x) or 's' for sin(x): ";
cin>>ch;
cout<<"\nEnter a,b for domain [a,b]: ";
cin>>a>>b;
cout<<"\nEnter N for divide the function: ";
cin>>n;
avg=(float)((a-b)/n);
if (ch=='c')
{
float temp=a;
for (i=0;i<n && temp<=b;i++)
{
sum+=0.5*(Cos(temp)+Cos(temp+avg))*avg;
temp+=avg;
}
}
else if (ch=='s')
{
float temp=a;
for (i=0;i<n && temp<=b;i++)
{
sum+=0.5*(Sin(temp)+Sin(temp+avg))*avg;
temp+=avg;
}
}
cout<<"\nResult: "<<sum;
getch();
}