From 483d63fa7249ad8d6020680c48c3cf6df35010b3 Mon Sep 17 00:00:00 2001 From: Santo Cariotti Date: Wed, 26 Apr 2017 16:37:39 +0200 Subject: Moved all C++ files into CPP folder --- cpp/borsa.cc | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 cpp/borsa.cc (limited to 'cpp/borsa.cc') 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 + +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; +} -- cgit v1.2.3-18-g5258