PROGRAM TO CHECK WHETHER A GIVEN NUMBER IS ARMSTRONG OR NOT

/*PROGRAM TO CHECK WHETHER A GIVEN NUMBER IS ARMSTRONG OR NOT*/

#include<conio.h>

#include<iostream.h>

class armstrong

{

int n,temp,rem,sum;

public:

void input();

void output();

};

void armstrong::input()

{

cout<<“Enter any number: “;

cin>>n;

}

void armstrong::output()

{

temp=n;

sum=0;

while(temp>0)

{

rem=temp%10;

temp=temp/10;

sum=sum+rem*rem*rem;

}

if(sum==n)

cout<<n<<” is armstrong number”;

else

cout<<n<<” is not an armstrong number”;

}

void main()

{

armstrong a1;

clrscr();

a1.input();

a1.output();

getch();

}

Leave a Reply

Your email address will not be published. Required fields are marked *