48 lines
954 B
C++
48 lines
954 B
C++
/*
|
|
Nome: Mario
|
|
Cognome: Montanari
|
|
*/
|
|
|
|
#include <iostream>
|
|
|
|
using namespace std;
|
|
|
|
typedef struct {
|
|
int numero;
|
|
} fattoriale;
|
|
|
|
fattoriale calcolo(fattoriale fattorialeNumero);
|
|
void stampaFattoriale(fattoriale fattorialeNumero);
|
|
|
|
int main(void) {
|
|
fattoriale fattorialeNumero;
|
|
|
|
cout << "Inserisci il numero di cui calcolare il fattoriale: ";
|
|
cin >> fattorialeNumero.numero;
|
|
|
|
cout << endl;
|
|
|
|
cout << "Numero da calcolare: " << fattorialeNumero.numero << "!" << endl;
|
|
|
|
cout << endl;
|
|
|
|
cout << "Calcolo del fattoriale: ";
|
|
stampaFattoriale(calcolo(fattorialeNumero));
|
|
|
|
return 0;
|
|
}
|
|
|
|
fattoriale calcolo(fattoriale fattorialeNumero) {
|
|
fattoriale risultato;
|
|
risultato.numero = 1;
|
|
|
|
for (int i = 1; i <= fattorialeNumero.numero; ++i) {
|
|
risultato.numero = risultato.numero * i;
|
|
}
|
|
|
|
return risultato;
|
|
}
|
|
|
|
void stampaFattoriale(fattoriale fattorialeNumero) {
|
|
cout << fattorialeNumero.numero << endl;
|
|
} |