Discussion topic: Contributed Answer/Explanation to Q. 1
To go to the homepage of this topic,
click here.
Home: asha_g_mca | Original Message | Reply | Subject: Contributed Answer/Explanation to Q. 1 | JAVA
class smith
{
void main(int n)
{
int d,sumd=0,sump=0,a=n,m,c=0;
//checking for Prime number
for(int i=1;i<=n;i++)
if (n%i==0) c++;
if (c>2)
{
//sum of digits
while(a!=0)
{d=a%10;
a=a/10;
sumd+=d;
}
//sum of prime factors
for(int i=2;i<=n;i++)
{
if (n%i==0) m=i;
//checking for prime factor
int f=0;
for(int j=1;j<=m;j++)
if (m%j==0) f++;
if (f==2)
{
if (m<10) sump+=m;
else{
a=m;
while(a!=0)
{d=a%10; a=a/10; sump+=d; }
}
}
}
if (sump==sumd)
System.out.println(n+"is a Smith number");
else
System.out.println(n+"is a Smith number");
}
else
System.out.println("You have entered a prime number.Prime cannot be a
smith number");
}
}
Posted at: Tue Sep 14 06:28:07 2010 (GMT) |
Page 1 of 1 | From: asha_g_mca | Reply 1 of 1 | Reply | | Subject: Re: Contributed Answer/Explanation to Q. 1 | good Posted at: Tue Sep 14 06:34:05 2010 (GMT)
|
Page 1 of 1
|
|
To post to this forum, you must be signed in as a Syvum member.
Please sign in / register as a member.