You are on page 1of 1

1 // Armstrong Number

2 // Coder: Manikya Varshney Date: 09/09/2022


3 #include<iostream>
4
5 using namespace std;
6 int count(int n){
7 int c=0;
8 while(n!=0){
9 n/=10;
10 c++;
11 }
12 return c;
13 }
14 int pow(int k,int p){
15 if(p==0){
16 return 1;
17 }
18 return k*pow(k,p-1);
19
20 }
21 int sum(int n,int d){
22 int s=0;
23 while(n>0){
24 int b=n%10;
25
26 s+=pow(b,d);
27 n/=10;}
28 return s;
29 }
30
31 int main (){
32 int t;
33 cout<<"Enter Number of test case "<<endl;
34 cin>>t;
35 for(int i=0;i<t;i++)
36 {int num;
37 cout<<"enter number"<<endl;
38 cin>>num;
39 int a=count(num);
40
41 int ans=sum(num,a);
42 if(ans==num){
43 cout<<"Number is Armstrong"<<endl;
44 }
45 else{
46 cout<<"Number is not Armstrong"<<endl;
47 }
48 cout<<endl;}
49 return 0;
50 }
51

You might also like