C++ Program to check number is Armstrong or not using Class and Object
Here you will get and learn the example code of C++ program to check number is Armstrong or not using Class and Object in C++ programming language.
Example Program to check number is Armstrong or not using Class and Object in C++
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 51 52 53 54 55 56 | #include <iostream> #include<cmath> using namespace std; class ArmstrongCheck { int k,num,tnum,ct=0,rem,sum, digits; public: void getdata() { cout << "Enter a positive number : "; cin >> num; tnum=num; while(tnum!=0) { k=tnum%10; tnum=tnum/10; ct++; } } void CalulationArms() { int temp = num; sum = 0; while (temp != 0) { rem = temp % 10; sum = sum + pow(rem,ct); temp = temp / 10; } } int isArmstrong() { if (num == sum) return 1; else return 0; } }; int main() { ArmstrongCheck A; A.getdata(); A.CalulationArms(); if (A.isArmstrong()) cout << "\nNumber is Armstrong"; else cout << "\nNumber is not Armstrong"; return 0; } |
Output 1
Enter a positive number : 153
Number is Armstrong
Output 2
Enter a positive number : 183
Number is not Armstrong
Output 3
Enter a positive number : 9474
Number is Armstrong
Check out our other C++ programming Examples