From ab8183f7a2036f7cb4714081063bb80a84757df4 Mon Sep 17 00:00:00 2001 From: Santo Cariotti Date: Fri, 20 Jan 2017 19:46:47 +0100 Subject: Add files via upload --- arrayMinMax.cc | 35 +++++++++++++++++++++++++++++++++++ borsa.cc | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+) create mode 100644 arrayMinMax.cc create mode 100644 borsa.cc diff --git a/arrayMinMax.cc b/arrayMinMax.cc new file mode 100644 index 0000000..be36903 --- /dev/null +++ b/arrayMinMax.cc @@ -0,0 +1,35 @@ +#include + +using namespace std; + +int main(void) +{ + int a[] = {5,14,9,8,10,65,32,1,6,78}; + int tot = sizeof a / sizeof(int); + int t, i, j, minore = a[0], maggiore = a[tot-1]; + + for(i = 0; i < tot; i++) + { + for(j = 0; j < tot-1; j++) + { + if(a[j] > a[j+1]){ + t = a[j+1]; + a[j+1] = a[j]; + a[j] = t; + } + } + } + + //for(i = 0; i < tot; i++) cout << a[i] << endl; + + /*for(int i = 0; i < tot; i++) + { + if(a[i] < minore) minore = a[i]; + else if(a[i] > maggiore) maggiore = a[i]; + }*/ + + cout << minore << endl; + cout << maggiore << endl; + + return 0; +} 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 + +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