Upload files to "funzioni"
This commit is contained in:
parent
2aa83f2510
commit
80d7295c60
|
@ -0,0 +1,51 @@
|
||||||
|
/*
|
||||||
|
AUTORE: Manuel Vichi
|
||||||
|
Inversione di un numero, complemento a 10, numero di cifre
|
||||||
|
*/
|
||||||
|
#include <iostream>
|
||||||
|
#include <array>
|
||||||
|
#include <vector>
|
||||||
|
#include <cstdlib>
|
||||||
|
using namespace std;
|
||||||
|
int invertiNumero(int numero) {
|
||||||
|
int resto = 0, invertito = 0, temp = numero;
|
||||||
|
do {
|
||||||
|
resto = temp % 10;
|
||||||
|
invertito = (invertito * 10) + resto;
|
||||||
|
temp = temp / 10;
|
||||||
|
} while (temp != 0);
|
||||||
|
return invertito;
|
||||||
|
}
|
||||||
|
|
||||||
|
int complementoA10(int numero) {
|
||||||
|
int cifre = 0, potenza = 1, complemento, temp = numero;
|
||||||
|
do {
|
||||||
|
temp = temp / 10;
|
||||||
|
cifre++;
|
||||||
|
} while (temp != 0);
|
||||||
|
do {
|
||||||
|
potenza = potenza * 10;
|
||||||
|
cifre--;
|
||||||
|
} while (cifre > 0);
|
||||||
|
complemento = potenza - numero;
|
||||||
|
return complemento;
|
||||||
|
}
|
||||||
|
|
||||||
|
int contaZeri(int numero) {
|
||||||
|
int zeri = 0, temp = numero;
|
||||||
|
while (temp > 0) {
|
||||||
|
if (temp % 10 == 0) {
|
||||||
|
zeri++;
|
||||||
|
}
|
||||||
|
temp /= 10; // Rimuoviamo l'ultima cifra
|
||||||
|
}
|
||||||
|
return zeri;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
int numero;
|
||||||
|
cout << "Inserisci un numero: ";
|
||||||
|
cin >> numero;
|
||||||
|
cout << endl << "Il numero invertito e': " << invertiNumero(numero) << endl << "Il complemento a 10 del numero e': " << complementoA10(numero) << endl << "Il numero di zeri nel numero e': " << contaZeri(numero) << endl;
|
||||||
|
return 0;
|
||||||
|
}
|
|
@ -0,0 +1,26 @@
|
||||||
|
/*
|
||||||
|
AUTORE: Manuel Vichi
|
||||||
|
Potenze
|
||||||
|
Work in Progress: Fare in modo che +1 mostri il segno
|
||||||
|
*/
|
||||||
|
#include <iostream>
|
||||||
|
#include <array>
|
||||||
|
#include <vector>
|
||||||
|
#include <cstdlib>
|
||||||
|
using namespace std;
|
||||||
|
int potenzaInteri(int base, int esponente) {
|
||||||
|
return base^esponente;
|
||||||
|
}
|
||||||
|
|
||||||
|
float potenza(float base, float esponente) {
|
||||||
|
return (float)base^esponente;
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned int potenzaNaturale(unsigned int base, unsigned int esponente) {
|
||||||
|
return base^esponente;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
cout << "Potenza intera: " << potenzaInteri(-2,3) << endl << "Potenza float: " << potenza(2.0f,5.9f) << endl << "Potenza naturale: " << potenzaNaturale(5,7) << endl;
|
||||||
|
return 0;
|
||||||
|
}
|
Loading…
Reference in New Issue