"The best way to cheer yourself up is to try to cheer somebody else up." Mark Twain

Monday, January 11, 2010

Check Armstrong no.


// Sum of the cube of all digits of a number is equal to the number , itself. 
//  153 = 1*1*1+5*5*5+3*3*3


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

void main()
{
  int a, dig , sum = 0;
cout<<"\n Enter A No.:";
cin>>a;

for(int i = a; i>0 ; i = i/10)
{
dig = i%10;
 sum = sum + dig*dig*dig;
}

if(sum == a)
cout<<"\n The no. is Armstrong No.";
else
cout<<"\n The no. is not a Armstrong No.";

getch();
}




No comments:

Post a Comment

C makes it easy to shoot yourself in the foot; C++ makes it harder, but when you do it blows your whole leg off.
Now Playing: Ballade Pour Adeline

About Me

My photo
I m an IT lecturer of a college. I love social-work. I want to do something beneficial for society before dying , that can promote our society, to some extent.