summaryrefslogtreecommitdiff
path: root/cpp/borsa.cc
diff options
context:
space:
mode:
authorSanto Cariotti <sancn@live.com>2017-04-26 16:37:39 +0200
committerSanto Cariotti <sancn@live.com>2017-04-26 16:37:39 +0200
commit483d63fa7249ad8d6020680c48c3cf6df35010b3 (patch)
tree2f8649e3ae6b42ace5011246285c9c450f004222 /cpp/borsa.cc
parent6c957dc4e01aee6ce9cae3c8342d04b0fd9ca9c4 (diff)
Moved all C++ files into CPP folder
Diffstat (limited to 'cpp/borsa.cc')
-rw-r--r--cpp/borsa.cc32
1 files changed, 32 insertions, 0 deletions
diff --git a/cpp/borsa.cc b/cpp/borsa.cc
new file mode 100644
index 0000000..05fdd85
--- /dev/null
+++ b/cpp/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;
+}