34 lines
803 B
C++
34 lines
803 B
C++
/*
|
|
AUTORE: Manuel Vichi
|
|
Elaborato 3
|
|
*/
|
|
#include <iostream>
|
|
using namespace std;
|
|
int main(void) {
|
|
unsigned int numero,invertito = 0,resto,complemento,cifre = 1,temp = 0,potenza = 1;
|
|
cout << "Inserisci un numero intero positivo: ";
|
|
cin >> numero;
|
|
cout << endl;
|
|
temp = numero;
|
|
//Inversione Cifre
|
|
while (temp > 0){
|
|
resto = numero % 10;
|
|
invertito = invertito * 10 + resto;
|
|
temp = (numero - resto) / 10;
|
|
}
|
|
temp = numero;
|
|
//Complemento a 10
|
|
do {
|
|
temp = temp / 10;
|
|
cifre++;
|
|
} while (temp != 0);
|
|
while (cifre > 0) {
|
|
potenza = potenza * 10;
|
|
cifre--;
|
|
}
|
|
complemento = potenza - numero;
|
|
cout << "Il numero " << numero << "invertito e': " << invertito << endl;
|
|
cout << "Il complemento a 10 di " << numero << " e': " << complemento << endl;
|
|
return 0;
|
|
}
|