summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSanto Cariotti <sancn@live.com>2017-02-15 19:45:37 +0100
committerGitHub <noreply@github.com>2017-02-15 19:45:37 +0100
commita058ecdd549034aaaa0a80f4ae19abba9183d830 (patch)
treec4fe410203389936e908c3590eb3e5c19afaf02a
parent881ffec87c9a10b599b7aa162f02669ceb0d89bd (diff)
Update and rename vettPositivi.cc to vettMul2.cc
-rw-r--r--vettMul2.cc (renamed from vettPositivi.cc)20
1 files changed, 19 insertions, 1 deletions
diff --git a/vettPositivi.cc b/vettMul2.cc
index d64aafe..5f45228 100644
--- a/vettPositivi.cc
+++ b/vettMul2.cc
@@ -2,10 +2,12 @@
/* dato un vettore di grandezza 100, stampare i valori caricati
precedentemente che sono multipli del numero 2 */
+
#include <iostream>
#include <time.h>
#include <stdlib.h>
#include <vector>
+#include <math.h>
using namespace std;
@@ -18,6 +20,22 @@ int n_rand(int num)
return num;
}
+bool potenza2(int num)
+{
+ bool x = false;
+
+ for(int i = 0; i < n; i++)
+ {
+ if(pow(2,i) == num) {
+ x = true;
+ break;
+ }
+ }
+
+ if(x) return true;
+ else return false;
+}
+
int main()
{
srand(time(0));
@@ -27,7 +45,7 @@ int main()
for(i = 0; i < n; i++) {
vett1[i] = n_rand(n_casuale);
- if((vett1[i] % 2) == 0)
+ if(potenza2(vett1[i]))
vett2.push_back(vett1[i]);
}