Search This Blog

Sunday, 15 September 2013

Checking a number is Armstrong or not in C++

Concept of Armstrong in C++

#include<iostream.h>
#include<conio.h>

void main()
{
 int n,rem,sum=0,temp;
 cout<<"Enter a number:";
 cin>>n;
 temp=n;
 while(n>0)
 {
   rem=n%10;
   sum=sum+rem*rem*rem;
   n=n/10;
 }
 if(temp==sum)
   cout<<"Entered number is a armstrong";
 else
 cout<<"Entered number is not armstrong";

 getch();
}

output



No comments:

Popular Posts