This repository has been archived by the owner on Jun 16, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ac15217
commit 8de1a26
Showing
8 changed files
with
246 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#include <iostream> | ||
#include <time.h> | ||
|
||
using namespace std; | ||
|
||
int main() { | ||
srand(time(0)); | ||
const int dim = 5; | ||
int v[dim]; | ||
|
||
for (int i=0; i<dim; i++) { | ||
v[i] = rand(); | ||
} | ||
|
||
for (int i=0; i<dim; i++) { | ||
cout << v[i] << endl; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#include <iostream> | ||
#include <time.h> | ||
|
||
using namespace std; | ||
|
||
const int somma(const int[], const int); | ||
inline const int rand_in_range(const int, const int); | ||
|
||
int main() { | ||
const int DIM = 5; | ||
const int RANGE_INF = 0, RANGE_SUP = 10; | ||
int v[DIM]; | ||
|
||
srand(time(0)); | ||
|
||
for (int i=0; i<DIM; i++) { // scorri in modo crescente per sfruttare cache line | ||
v[i] = rand_in_range(RANGE_INF, RANGE_SUP); | ||
cout << v[i] << endl; | ||
} | ||
|
||
cout << endl << somma(v, DIM) << endl; | ||
} | ||
|
||
const int somma(const int v[], const int dim) { | ||
int somma = 0; | ||
for (int i=0; i<dim; i++) { | ||
somma += v[i]; | ||
} | ||
return somma; | ||
} | ||
|
||
inline const int rand_in_range(const int inf, const int sup) { | ||
return rand()%(sup-inf+1) + inf; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#include <iostream> | ||
#include <time.h> | ||
|
||
using namespace std; | ||
|
||
inline int max(const int a, const int b); | ||
inline int rand_in_range(const int inf, const int sup); | ||
|
||
int main() { | ||
srand(time(0)); | ||
const int dim = 5; | ||
int v[dim]; | ||
|
||
// generazione e stampa | ||
for (int i=0; i<dim; i++) { | ||
v[i] = rand_in_range(1, 100); | ||
cout << v[i] << endl; | ||
} | ||
|
||
// ricerca massimo | ||
int massimo = v[0]; | ||
for (int i=0; i<dim; i++) { | ||
massimo = max(massimo, v[i]); | ||
} | ||
|
||
cout << "Il valore massimo presente nel vettore è: " << massimo << endl; | ||
return 0; | ||
} | ||
|
||
inline int max(const int a, const int b) { | ||
return a > b ? a : b; | ||
} | ||
|
||
inline int rand_in_range(const int inf, const int sup) { | ||
return rand()%(sup-inf) + inf; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#include <iostream> | ||
#include <time.h> | ||
|
||
using namespace std; | ||
|
||
inline int max(const int a, const int b); | ||
inline int rand_in_range(const int inf, const int sup); | ||
|
||
int main() { | ||
srand(time(0)); | ||
const int dim = 5; | ||
int v[dim]; | ||
|
||
// generazione e stampa | ||
for (int i=0; i<dim; i++) { | ||
v[i] = rand_in_range(1, 100); | ||
cout << v[i] << endl; | ||
} | ||
|
||
// ricerca massimo | ||
int index = 0; | ||
for (int i=0; i<dim; i++) { | ||
if (v[index] < v[i]) { | ||
index = i; | ||
} | ||
} | ||
|
||
cout << "Il valore massimo presente nel vettore è: " << v[index] << endl; | ||
return 0; | ||
} | ||
|
||
inline int max(const int a, const int b) { | ||
return a > b ? a : b; | ||
} | ||
|
||
inline int rand_in_range(const int inf, const int sup) { | ||
return rand()%(sup-inf) + inf; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#include <iostream> | ||
#include <time.h> | ||
|
||
using namespace std; | ||
|
||
void copia_pari(const int[], const int, int[], int&); | ||
inline const int rand_in_range(const int, const int); | ||
|
||
int main() { | ||
const int DIM = 5; | ||
const int RANGE_INF = 0, RANGE_SUP = 10; | ||
int v[DIM], pari[DIM]; | ||
int pari_dim = 0; | ||
|
||
srand(time(0)); | ||
|
||
for (int i=0; i<DIM; i++) { // scorri in modo crescente per sfruttare cache line | ||
v[i] = rand_in_range(RANGE_INF, RANGE_SUP); | ||
cout << v[i] << endl; | ||
} | ||
|
||
copia_pari(v, DIM, pari, pari_dim); | ||
|
||
cout << endl; | ||
for (int i=0; i<pari_dim; i++) { | ||
cout << pari[i] << endl; | ||
} | ||
} | ||
|
||
// dim_out verrà inizializzato a zero | ||
// output[] deve avere una dimensione pari o superiore a dim_in | ||
void copia_pari(const int input[], const int dim_in, int output[], int &dim_out) { | ||
dim_out = 0; | ||
for (int i=0; i<dim_in; i++) { | ||
if (input[i]%2 == 0) | ||
output[dim_out++] = input[i]; | ||
} | ||
} | ||
|
||
inline const int rand_in_range(const int inf, const int sup) { | ||
return rand()%(sup-inf+1) + inf; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#include <iostream> | ||
#include <time.h> | ||
|
||
using namespace std; | ||
|
||
void raddoppia_array(int[], const int); | ||
inline const int rand_in_range(const int, const int); | ||
|
||
int main() { | ||
const int DIM = 5; | ||
const int RANGE_INF = 0, RANGE_SUP = 10; | ||
int v[DIM]; | ||
|
||
srand(time(0)); | ||
|
||
for (int i=0; i<DIM; i++) { // scorri in modo crescente per sfruttare cache line | ||
v[i] = rand_in_range(RANGE_INF, RANGE_SUP); | ||
cout << v[i] << endl; | ||
} | ||
|
||
raddoppia_array(v, DIM); | ||
|
||
cout << endl; | ||
for (int i=0; i<DIM; i++) { | ||
cout << v[i] << endl; | ||
} | ||
} | ||
|
||
void raddoppia_array(int v[], const int dim) { | ||
for (int i=0; i<dim; i++) { | ||
v[i] *= 2; | ||
} | ||
} | ||
|
||
inline const int rand_in_range(const int inf, const int sup) { | ||
return rand()%(sup-inf+1) + inf; | ||
} |