Search This Blog

Monday, 12 November 2012

Write a c++ program for checking a given number is armstrong or not using constructor

#include<iostream.h>
#include<conio.h>
class Arm{
int n;
public:
Arm(int);
};
Arm::Arm(int X)
{
int n1=x,d,s;
n=x;
s=0;
while(n>0)
{
d=n%10;
s=s+d*d*d;
n=n/10;
}
cout<<"Given Number"<<n1<<"is";
if(s==n1)
cout<<"Armstrong";
else
cout<<"Not Armstron";
}
void main()
{
clrscr();
Arm A(153);
getch();
}

Output:
Given Number 234 is Not Armstrong


No comments:

Post a Comment