Skip to content
This repository has been archived by the owner on Jun 16, 2023. It is now read-only.

Commit

Permalink
recupera esercizi arretrati
Browse files Browse the repository at this point in the history
  • Loading branch information
mc-cat-tty committed Dec 20, 2021
1 parent 04cd758 commit 27c4e0c
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 0 deletions.
25 changes: 25 additions & 0 deletions esercitazioni/base_10_a_2.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#include <iostream>
#include <math.h>

using namespace std;

int main() {
const int base_partenza = 10;
const int base_arrivo = 2;

int num_10; // numero preso in input
int num_2 = 0; // risultato
int count = 0;

cout << "Numero in base 10: "; cin >> num_10;

while (num_10!=0) {
num_2 += (num_10%base_arrivo) * pow(base_partenza, count);
num_10 /= base_arrivo;
count++;
}

cout << "Numero in base 2: " << num_2 << endl;

return 0;
}
25 changes: 25 additions & 0 deletions esercitazioni/base_2_a_10.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#include <iostream>
#include <math.h>

using namespace std;

int main() {
const int base_partenza = 2;
const int base_arrivo = 10;

int num_2; // numero preso in input
int num_10 = 0; // risultato
int count = 0; // contatore iterazioni

cout << "Numero base 2: "; cin >> num_2;

while (num_2!=0) {
num_10 += (num_2%base_arrivo) * pow(base_partenza, count);
num_2 /= 10;
count++;
}

cout << "Numero base 10: " << num_10 << endl;

return 0;
}
12 changes: 12 additions & 0 deletions esercitazioni/stampa_hex.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include <iostream>
#include <iomanip>

using namespace std;

int main() {
cout << "Numero: ";
int n;
cin >> n;
cout << "Numero in base 16: " << hex << n << endl;
cout << "Numero in base 10: " << dec << n << endl; // riporto lo stream allo stato normale
}

0 comments on commit 27c4e0c

Please sign in to comment.