37 lines
597 B
C++
37 lines
597 B
C++
#include <iostream>
|
|
|
|
using namespace std;
|
|
|
|
int main(void) {
|
|
int decimale;
|
|
|
|
cout << "Inserisci un numero decimale: ";
|
|
cin >> decimale;
|
|
|
|
if (decimale < 0 || decimale > 255) {
|
|
cout << "Numero non valido!" << endl;
|
|
|
|
return 0;
|
|
}
|
|
|
|
char ottale[4] = {0};
|
|
int i = 0;
|
|
|
|
if (decimale == 0) {
|
|
ottale[i++] = '0';
|
|
}
|
|
|
|
while (decimale > 0) {
|
|
ottale[i++] = '0' + (decimale % 8);
|
|
decimale = decimale / 8;
|
|
}
|
|
ottale[i] = '\0';
|
|
|
|
cout << "Numero ottale: ";
|
|
for (int j = i - 1; j >= 0; j--) {
|
|
cout << ottale[j];
|
|
}
|
|
cout << endl;
|
|
|
|
return 0;
|
|
} |