From a8ccc20e4b25a06e4a5845cadcc4425463ddff91 Mon Sep 17 00:00:00 2001 From: DarkFlame Date: Wed, 18 Oct 2023 18:54:17 +0200 Subject: [PATCH] ho svolto l'esercizio conversione binaria --- exercises/binary_converter.cpp | 35 ++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/exercises/binary_converter.cpp b/exercises/binary_converter.cpp index 19bf37d..c578640 100644 --- a/exercises/binary_converter.cpp +++ b/exercises/binary_converter.cpp @@ -5,3 +5,38 @@ Insert first number: 8 The binary number is: 1000 */ + +#include +#include + +using namespace std; + + +int main (){ + + int n; + + cout <<"Inserisci un Numero "; + + cin >>n; + + while (n > 0){ + + if (n%2 == 0 ){ + + cout<<0; + } + + else{ + + cout<<1; + } + // si legge al contrario + n = n/2; + } + + +} + + +