Class 11 Assignment 6 (Prac)
Class 11 Assignment 6 (Prac)
Examples: 1
Enter a Number : 85
Sum of Digit = 13
Sum of Prime Factor = 13
It is a Smith Number
Examples: 2
Enter a Number : 666
Sum of Digit = 18
Sum of Prime Factor = 18
It is a Smith Number
Examples: 3
Enter a Number : 999
Sum of Digit = 27
Sum of Prime Factor = 19
It is Not a Smith Number
Write a program to input a number and display whether the number is a Smith number or not.
import java.util.*;
class s11q2
{
public static void main()
{
Scanner in=new Scanner(System.in);
int n,r,ds=0,fs=0,i,j;
System.out.print("Enter a number ");
n=in.nextInt();
for(i=n;i!=0;i=i/10)
{
r=i%10;
ds=ds+r;
}
for(i=2;i<=n;i++)
{
if(n%i==0)
{
for(j=i;j!=0;j=j/10)
{
r=j%10;
fs=fs+r;
}
n=n/i;
i--;
}
}
if(ds==fs)
{
System.out.print("It is a Smith number ");
}
else
{
System.out.print("It is not a Smith number ");
}
}
}