C++ Program to check whether the number is Armstrong or not

 What is an Armstrong Number?

Armstrong number is a number that is equal to the sum of cube of its digits. Some examples of armstrong number are 153,371,370,407 etc.







Program:

 #include<iostream>  
 using namespace std;  
   
 int main()  
 {  
   int n,rem,sum=0;  
   cout<<"Enter n: ";  
   cin>>n;  
     
   while(n!=0)  
   {  
     rem=n%10;  
     sum+=rem*rem*rem;  
     n/=10;  
       
   }  
   if(sum==n)  
   cout<<n<<" is an Armstrong Number";  
   
   else  
   cout<<n<<" is not an Armstrong Number";  
   
   return 0;  
 }  

Output:

Enter n: 153
153 is an Armstrong Number
C++ Program to check whether the number is Armstrong or not C++ Program to check whether the number is Armstrong or not Reviewed by Beast Coder on January 28, 2021 Rating: 5

No comments:

Powered by Blogger.