summaryrefslogtreecommitdiff
path: root/cpp/borsa.cc
diff options
context:
space:
mode:
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;
+}