This is a Tutorial site for school and college students. Programs and technical analysis on BlueJ for ICSE and ISC Students, C programming, C++ programming and Data structure through C programming language are posted here. Engineering college students can get help on C and C++ languages from this site.
It is a composite number in which, the sum of its digits is equal to the sum of the digits in its prime factors. In 378 the sum of the digits is 3+7+8=18. The prime factors of 378 are 2, 3, 3, 3, 7. Here all the prime factors are single digit numbers and their sum is 2+3+3+3+7-18. So 378 is a
smith number. Again if we take the case of 22, the sum of the digits is 2+2=4 and the prime factors are 2 and 11. Since 11 is a two digit number, the sum of the digits of the factors is 2+1+1=4. So 22 is a Smith number.
The first few Smith numbers are: 4, 22, 27, 58, 85, 94, 121, 166, 202, 265, 274, 319, 346,
How to proceed on this program to check Smith number
Firstly sum of the digits of the entered number is to be stored in a variable. Next step is to find out the factors and checking the numbers whether they are prime or not. If found prime factor then the sum of the digits of the factor number is stored in another counter variable and the same process is followed for all prime factor numbers. Whenever any prime factor is found, the original entered number is tried with the same number and the original number is divided by the prime factor number.
Codes of the BlueJ program on Smith number checking
System.out.println(no+ " is not a smith number.");
private int sumOfDigits(int n)
private boolean prime(int n)
public static void main(String args)throws Exception
smith1 obj=new smith1();
Technical analysis of the Smith number checking program
Two variables ‘sum’ and ‘sumfactors’ are used in this program to store sum of the digits of the entered number and sum of the digits of the prime factors of the entered number. Three functions are defined in this program to perform the job of checking Smith number. Function ‘takeNumber()’ takes the number from user, invokes the other function ‘int sumOfDigits()’ which returns the sum of the digits and store in variable ‘sum’. Next the factors are generated and passed to another function ‘boolean prime()’ to check whether the number is prime or not. If any factor is not prime, the process of finding the next factor is continued. If the factor is found to be prime, sum of the digits of the factor number is calculated and stored in the other counter variable ‘sumfactors’. In such case, the process of finding prime factor number is continues with the same factor and the ntered number is reduced by dividing the entered number by the prime factor. At the end both the entered number and the sum of the digits of prime factor numbers are checked .