forked from Sjsingh101/Basic-C-Programs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArmstrong.cpp
More file actions
36 lines (30 loc) · 689 Bytes
/
Armstrong.cpp
File metadata and controls
36 lines (30 loc) · 689 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
#include <iostream>
using namespace std;
bool checkArmstrongNumber(int num);
int main(){
int num;
bool flag;
cout<<"Enter a positive integer: ";
cin>>num;
flag = checkArmstrongNumber(num);
if(flag == true)
cout<<num<<" is an Armstrong number.";
else
cout<<num<<" is not an Armstrong number.";
return 0;
}
bool checkArmstrongNumber(int num) {
int temp, sum=0, digit;
bool isArm;
temp = num;
while(temp != 0) {
digit = temp % 10;
sum = sum +(digit * digit * digit);
temp = temp/10;
}
if (sum==num)
isArm = true;
else
isArm = false;
return isArm;
}