Thursday , 27 July 2017
Latest Posts
Home » Class 10 » Program to check for Smith Number [ISC 2008 Practical]

# Program to check for Smith Number [ISC 2008 Practical]

#### Question:

Smith number is a composite number, the sum of whose digits is the sum of the digits of its prime factors obtained as a result of prime factorization (excluding 1). The first few such numbers are 4, 22, 27, 58, 85, 94, 121 ………………..

Examples:

1.  666

Prime factors are 2, 3, 3, and 37
Sum of the digits are (6+6+6) = 18
Sum of the digits of the factors (2+3+3+(3+7)) = 18

2.   4937775

Prime factors are 3, 5, 5, 65837
Sum of the digits are (4+9+3+7+7+7+5) = 42
Sum of the digits of the factors (3+5+5+(6+5+8+3+7)) = 42

Write a program to input a number and display whether the number is a Smith number or not.

Sample data:

Input             94          Output             SMITH Number

Input             102        Output             NOT SMITH Number

Input             666        Output             SMITH Number

Input             999        Output             NOT SMITH Number

#### Programming Code:

/**
* The class Smith inputs a number and checks whether it is a Smith Number or not
* @author : www.javaforschool.com
* @Program Type : BlueJ Program - Java
* @Question Year : ISC Practical 2008 Question 1
*/

import java.io.*;
class Smith
{
//function for finding sum of digits
int sumDig(int n)
{
int s=0;
while(n>0)
{
s=s+n%10;
n=n/10;
}
return s;
}

//function for generating prime factors and finding their sum
int sumPrimeFact(int n)
{
int i=2, sum=0;
while(n>1)
{
if(n%i==0)
{
sum=sum+sumDig(i); //Here 'i' is the prime factor of 'n' and we are finding its sum
n=n/i;
}
else
i++;
}
return sum;
}

public static void main(String args[]) throws IOException
{
Smith ob=new Smith();
System.out.print("Enter a Number : ");
int a=ob.sumDig(n);// finding sum of digit
int b=ob.sumPrimeFact(n); //finding sum of prime factors

System.out.println("Sum of Digit = "+a);
System.out.println("Sum of Prime Factor = "+b);

if(a==b)
System.out.print("It is a Smith Number");
else
System.out.print("It is Not a Smith Number");
}
}

#### Output:

1. Enter a Number : 94
Sum of Digit = 13
Sum of Prime Factor = 13
It is a Smith Number

2. Enter a Number : 102
Sum of Digit = 3
Sum of Prime Factor = 13
It is Not a Smith Number

3. Enter a Number : 4937775
Sum of Digit = 42
Sum of Prime Factor = 42
It is a Smith Number

## [Question 2] ISC 2017 Computer Practical Paper Solved – Quiz Result

Solution of Program 2 of ISC 2017 Computer Science Paper 2 (Practical) Exam. Java program to input the answers of each participant row-wise and calculate their marks

1. sir when iam using scanner for checking smith
when iam writing
int n=ob.nextInt();
it showing error and saying
cannot find symbol variable- method.nextInt();

2. Mahender Dwivedi

Help full for students