Wednesday 18 December 2013

Armstrong Number Using C++

/*Armstrong Number  Using C++ Program  CHECK THE GIVEN NUMBER IS ARMSTRONG OR NOT

FOR EXAMPLE
153/1^3+5^3+3^3=153
*/
#include<iostream.h>
#include<conio.h>
void main()
{
  clrscr();
  int i,n,m,re,sum=0;
  cout<<"enter the required number";
  cin>>n;
  m=n;
  while(m>0)
   {
    re=m%10;
    m=m/10;
    sum=sum+re*re*re;
   }
  if(sum==n)
   {
    cout<<"given number"<<n<<"is armstrong";
   }
  else
   {
    cout<<"given number"<<<n<"is not armstrong";
   }
  getch();
}

No comments:

Post a Comment