Saturday, March 1, 2014

C++ Program to check whether number is Armstrong number

#include<iostream.h>
int main()
{
      int sum,temp,rem,n;
     cout<<"Enter the number \n";
     cin>>n;
     cout<<" Entered number is \t";
     cout<<n;
     cout<<"\n";
     sum=0; 
     temp=n;
      do
        {
                rem=n%10;
                n=n/10;
                sum=sum+rem*rem*rem;
           }while(n!=0);
     if(sum==temp)
            cout<<"This is Armstrong number.\n";
   else
           cout<<"This is not Armstrong number.\n";
return 0;
}

Output:-
Enter the number
371
Entered number is    371
This is Armstrong number.

No comments:

Post a Comment

Happy Independence Day August 15th

 Here's a message for India's Independence Day (August 15th): "शुभ स्वतंत्रता दिवस! आजादी की 79वीं वर्षगांठ पर, आइए हम अपने देश...