-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharmstrong2.cpp
More file actions
41 lines (39 loc) · 768 Bytes
/
armstrong2.cpp
File metadata and controls
41 lines (39 loc) · 768 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
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
bool armstrong(int n)
{
string s = to_string(n);
int potenza = s.size();
int risultato = 0;
for(int i = 0; i < potenza; i++)
{
int singola_cifra = (int)s[i] - (int)'0';
risultato = risultato + pow(singola_cifra, potenza);
}
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;
}