Friday 25 October 2013

Magic Number By Recursion

class Magic
{
int n;
Magic()
{
n=0;
}
void getnum(int nn)
{
n=nn;
}
int SumOfDigit(int nn)
{
int s=0,x;
while(nn!=0)
{
x=nn%10;
nn=nn/10;
s=s+x;
}
return s;
}
void isMagic()
{
int x=n,c,y;
do
{
c=0;
x=SumOfDigit(x);
y=x;
while(y!=0)
{
y=y/10;
c++;
}
}
while(c!=1);
if(x==1)
{
System.out.println("No. is magic");
}
else
System.out.println("No. is not magic");
}
}

No comments:

Post a Comment