-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharmstrong3.cpp
More file actions
50 lines (46 loc) · 879 Bytes
/
armstrong3.cpp
File metadata and controls
50 lines (46 loc) · 879 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
bool armstrong(int n)
{
int n_copia = n;
int numero_cifre=0;
int risultato = 0;
while(n_copia > 0)
{
numero_cifre++;
n_copia = n_copia / 10;
}
n_copia=n;
while(n_copia > 0)
{
int singola_cifra = n_copia % 10;
risultato = risultato + pow(singola_cifra, numero_cifre);
n_copia = n_copia / 10;
}
if(risultato == n)
{
return true;
}
else
{
return false;
}
}
int main()
{
int n;
cout<<"inserisci un numero: ";
cin>>n;
bool armstrong_number= armstrong(n);
if(armstrong_number == true)
{
cout<<"il numero "<<n<<" e' un numero di Armstrong!!!";
}
else
{
cout<<"il numero "<<n<<" NON e' un numero di Armstrong!!!";
}
return 0;
}