summaryrefslogtreecommitdiff
path: root/borsa.cc
diff options
context:
space:
mode:
authorSanto Cariotti <sancn@live.com>2017-01-20 19:46:47 +0100
committerGitHub <noreply@github.com>2017-01-20 19:46:47 +0100
commitab8183f7a2036f7cb4714081063bb80a84757df4 (patch)
tree64d3eb3c66cbe20432f99218c56b413f98b3063b /borsa.cc
parentaf87fe2015e4634ed48ced8c56a702a0742f6ef9 (diff)
Add files via upload
Diffstat (limited to 'borsa.cc')
-rw-r--r--borsa.cc32
1 files changed, 32 insertions, 0 deletions
diff --git a/borsa.cc b/borsa.cc
new file mode 100644
index 0000000..05fdd85
--- /dev/null
+++ b/borsa.cc
@@ -0,0 +1,32 @@
+#include <iostream>
+
+using namespace std;
+
+int main(void)
+{
+ int a[] = {13,24,7,8,6,15,2,21,17,7,3,19,20,1};
+ int minore, diffp, diff = 0, x, y;
+ int tot = sizeof a/sizeof(int);
+
+ for(int i = 0; i < tot; i++)
+ {
+ minore = a[i];
+
+ for(int j = i; j < tot-1; j++)
+ {
+ if(a[j] == minore) continue;
+ else if(a[j] > minore) diffp = a[j] - minore;
+ if(diffp > diff && diffp > 0) {
+ x = i;
+ y = j;
+ diff = diffp;
+ }
+ }
+ }
+
+ cout << "Ti conviene comprare a " << a[x] << " giorno " << x+1 << " e vendere a " << a[y] << " giorno " << y+1 << endl;
+ cout << "Il tuo guadagno sarebbe: " << diff;
+
+
+ return 0;
+}