-
Notifications
You must be signed in to change notification settings - Fork 60
Expand file tree
/
Copy pathStock Prices using graph Peaks.cpp
More file actions
69 lines (53 loc) · 1004 Bytes
/
Stock Prices using graph Peaks.cpp
File metadata and controls
69 lines (53 loc) · 1004 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
66
67
68
69
#include<iostream>
#include<cstdio>
#include<vector>
using namespace std;
#include<iostream>
#include<cstdio>
using namespace std;
int peak[100];
int func(int *a,int n){
peak[0]=a[0];
int j=1,i,profit=0;
for(i=0;i<n;i++)
cout<<a[i]<<" ";
cout<<endl;
for(i=1;i<n-1;i++){
if(a[i]>a[i-1]&&a[i]>a[i+1])
{ //cout<<"MAX"<<a[i]<<" ";
peak[j++]=a[i];}
if(a[i]<a[i-1]&&a[i]<a[i+1])
{ //cout<<"MIN"<<a[i]<<" ";
peak[j++]=a[i];
}
}
peak[j]=a[n-1];
for(i=0;i<=j;i++)
cout<<peak[i]<<" ";
cout<<endl;
if(peak[1]>peak[0]){
for(i=1;i<=j;i+=2){
profit+= peak[i]-peak[i-1];
}
}
else{
for(i=2;i<=j;i+=2){
profit+= peak[i]-peak[i-1];
}
}
return profit;
}
int main(){
int n=10;
int a[]={11 ,7 ,10, 9, 13, 14, 10, 15, 12, 10};
/*cout<<"Enter no of days: ";
cin>>n;
int a[n+1];
int i;
cout<<"Enter prices :";
for(i=0;i<n;i++){
cin>>a[i];
}*/
cout<<endl<<func(a,n);
return 0;
}